小编tuc*_*t07的帖子

ASP.NET下载处理程序在IE中运行但不在Chrome中运行

我有一个下载处理程序,将在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)

c# asp.net ashx

3
推荐指数
1
解决办法
4319
查看次数

标签 统计

ashx ×1

asp.net ×1

c# ×1