简体   繁体   English

如何从asp.net 处理程序文件打开新的浏览器窗口?

[英]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.下面的代码在 Visual Studio 的调试中工作正常,但是当我将它发布到 IIS 服务器时不起作用。 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?问题是 System.Diagnostics.Process.Start 是否有任何替代方法可以在新窗口或选项卡中打开 url? Or how to make Process.Strat work in IIS?或者如何使 Process.Strat 在 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).如果您希望您的客户端打开一个文档,那么您需要创建一个响应,在响应中写入文件的内容并指定 MIME 类型(在 ContentType 属性中)。 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).这样,客户端的浏览器将确定用于打开该文档的程序(例如 ContentType“application/pdf”用 Acrobat 打开,“application/msword”用 Microsoft Word 打开等)。

See: ASP.NET file download from server And http://www.sitepoint.com/web-foundations/mime-types-summary-list/请参阅: 从服务器下载 ASP.NET 文件http://www.sitepoint.com/web-foundations/mime-types-summary-list/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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