-1

This copy button functionality is working in localhost. But when deploy it into server it's not working on server side.

protected void btnCopy_Click(object sender, EventArgs e)
    {  
        try
        {
            Thread myth;
            myth = new Thread(new System.Threading.ThreadStart(CallSaveDialog));
            myth.ApartmentState = ApartmentState.STA;
            myth.Start();
            lblok.Text = "URL Copied to Clipboard, Use CTRL+V to Paste";
        }
        catch (Exception ex)
        {

            Class_login abc = new Class_login();
            abc.writeerrorlog(ex.Message);

        }
       
     
    }
    void CallSaveDialog() { System.Windows.Forms.Clipboard.SetText(TxtUrl.Text);  }
derloopkat
  • 6,232
  • 16
  • 38
  • 45

1 Answers1

3

This code:

System.Windows.Forms.Clipboard.SetText(TxtUrl.Text);

Runs on the web server. It sets the text to the clipboard of the user executing your web application, which usually is someone named IIS AppPool\Sitename. This user is not the visitor of your website, it is the server process that is running your .NET code.

It works on your development machine ("localhost"), because IIS Express runs as your user.

The solution is to do this using JavaScript: How do I copy to the clipboard in JavaScript?

CodeCaster
  • 147,647
  • 23
  • 218
  • 272