-1

Code below works fine in debug from visual studio but when I publish it to IIS server doesn't work. Just nothing happens. I'm guessing some security issues. Question is if there are any alternatives for System.Diagnostics.Process.Start to open an url in new window or tab? Or how to make Process.Strat work in IIS? thanks

public void ProcessRequest(HttpContext context)
    {
        Context = context;
        if (context.Request.QueryString["path"] == null)
        {
            return;
        }
        string path = Context.Server.UrlDecode(Context.Request.QueryString["path"]);

        var item = DataServer.GetItem(path);
        if (item == null) return;

        System.Diagnostics.Process.Start(item["sourcePath"].ToString());
}
Zulu Z
  • 1,103
  • 5
  • 14
  • 27
  • 5
    You need to understand the difference between _client-side_ code and _server-side_ code. You can't do that. – SLaks Mar 31 '16 at 23:52
  • you don't understand the question and problem. This code works in debug. – Zulu Z Apr 01 '16 at 00:16
  • 1
    @ZuluZ It works in debug because when debugging, your server and client is the same machine. – vesan Apr 01 '16 at 00:16
  • Exactly. You need to understand the difference between the client and the server. – SLaks Apr 01 '16 at 02:42

1 Answers1

1

Your file is being opened at server side and that's why client see nothing. If you want your client to open a document then you need to create a response, write the content of the file in the response and specify mime type (in ContentType property). That way client's browser will figure out what program to use for opening that document (for example ContentType "application/pdf" opens with Acrobat, "application/msword" opens with Microsoft Word, etc).

See: ASP.NET file download from server And http://www.sitepoint.com/web-foundations/mime-types-summary-list/

Community
  • 1
  • 1
derloopkat
  • 6,232
  • 16
  • 38
  • 45
  • nice example, thanks but what if I want to open url to b opened in IE not a file? – Zulu Z Apr 01 '16 at 11:14
  • Then content disposition should be inline instead of attachment. In that case IE needs to have the plugins for correctly displaying that mime type on browser instead of calling an external application. – derloopkat Apr 01 '16 at 11:32
  • the problem is though I don't want to open a file but aspx page. – Zulu Z Apr 01 '16 at 23:29
  • Add an aspx and put the code for generating response for example in the page load event. Content-Disposition is inline. – derloopkat Apr 01 '16 at 23:59