我有一个下载处理程序,将在IE中下载该文件但在chrome中它会尝试下载自己.我的意思是Chrome意味着Chrome会尝试下载名为downloadhandler.ashx的文件.处理程序的代码是
<%@ WebHandler Language="C#" Class="DownloadHandler" %>
using System;
using System.Web;
public class DownloadHandler : IHttpHandler
{
public void ProcessRequest(HttpContext context)
{
string file = "";
// get the file name from the querystring
if (context.Request.QueryString["Filepath"] != null)
{
file = context.Request.QueryString["Filepath"].ToString();
}
string filename = context.Server.MapPath("~/Minutes/" + file);
System.IO.FileInfo fileInfo = new System.IO.FileInfo(filename);
try
{
if (fileInfo.Exists)
{
context.Response.Clear();
context.Response.AddHeader("Content-Disposition", "inline;attachment; filename=\"" + fileInfo.Name + "\"");
context.Response.AddHeader("Content-Length", fileInfo.Length.ToString());
context.Response.ContentType = "application/octet-stream";
context.Response.TransmitFile(fileInfo.FullName);
context.Response.Flush();
}
else
{
throw new Exception("File not …Run Code Online (Sandbox Code Playgroud)