0
我有一个通用的处理程序,根据查询字符串服务PDF的。我以前没有使用过的处理程序,但是当我建立我得到2个奇怪的错误,我无法找到一个解决方案:错误是:ASP.NET通用处理程序编译错误
命名空间不能直接包含成员如字段或 方法
关键字,标识符或字符串后面逐字 符预期:@
这里是代码
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace Center
{
/// <summary>
/// This tracks user opens serves the proper PDF by querystring value f
/// </summary>
public class GetFile : IHttpHandler
{
public void ProcessRequest(HttpContext context)
{
//Get file reference
if (context.Request.QueryString["f"] != null)
{
string file;
string fullFilePath;
string fileName;
file = context.Request.QueryString["f"];
switch (file)
{
case "Access":
App_Code.bi.LogFileDownload("Access Fact Sheet", context.Session["UserID"].ToString());
fullFilePath = "files/Access2013.pdf#zoom=100";
fileName = "Access2013.pdf";
context.Response.Clear();
context.Response.ContentType = "application/pdf";
context.Response.AddHeader("Content-Disposition", "attachment; filename=" + fileName);
context.Response.TransmitFile(fullFilePath);
context.Response.End();
break;
case "MobileApp":
fullFilePath = "files/mobile_app.pdf#zoom=100";
fileName = "mobile_app.pdf";
context.Response.Clear();
context.Response.ContentType = "application/pdf";
context.Response.AddHeader("Content-Disposition", "attachment; filename=" + fileName);
context.Response.TransmitFile(fullFilePath);
context.Response.End();
break;
case "BillingFact":
fullFilePath = "files/billing_factsheet.pdf#zoom=100";
fileName = "billing_factsheet.pdf";
context.Response.Clear();
context.Response.ContentType = "application/pdf";
context.Response.AddHeader("Content-Disposition", "attachment; filename=" + fileName);
context.Response.TransmitFile(fullFilePath);
context.Response.End();
break;
case "HistoricalFact":
fullFilePath = "files/Implementation.pdf#zoom=100";
fileName = "Implementation.pdf";
context.Response.Clear();
context.Response.ContentType = "application/pdf";
context.Response.AddHeader("Content-Disposition", "attachment; filename=" + fileName);
context.Response.TransmitFile(fullFilePath);
context.Response.End();
break;
case "ImplementationKit":
App_Code.bi.LogFileDownload("Implementation Kit", context.Session["UserID"].ToString());
fullFilePath = "files/Implementation_kit.pdf#zoom=100";
fileName = "Implementation.pdf";
context.Response.Clear();
context.Response.ContentType = "application/pdf";
context.Response.AddHeader("Content-Disposition", "attachment; filename=" + fileName);
context.Response.TransmitFile(fullFilePath);
context.Response.End();
break;
}
}
}
public bool IsReusable
{
get
{
return false;
}
}
}
}
ASHX file
---------------
<%@ WebHandler Language="C#" CodeBehind="GetFile.ashx.cs" Class="Center.GetFile" %>
我可以准确地复制你的代码(注释掉两个' APP_Code'线),它工作正常。此外,如果你看我的[先前发布]中的示例(http://stackoverflow.com/questions/19123961/filehandler-in-asp-net/19124733#19124733),你不必乱七八糟的查询字符串和开关语句......为什么不直接链接到PDF?每次添加新文件时,这条路线都会很痛苦。 – MikeSmithDev
感谢@MikeSmithDev,我将改变这种方式来删除switch语句,并且只要在测试过程中确定这个文件信息从数据库中提取出来,它就是一种“概念验证”解决方案,我只是想确定它在我清理之前工作。它没有建立,因为ashx文件因某种原因被设置为编译。 –