简体   繁体   中英

how to open new browser window from asp.net handler file?

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());
}

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/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM