クエリ文字列に応じて PDF を提供する汎用ハンドラーがあります。以前にハンドラーを使用したことはありませんが、ビルドすると、解決策が見つからない2つの奇妙なエラーが発生します。エラーは次のとおりです。
名前空間には、フィールドやメソッドなどのメンバーを直接含めることはできません
verbatim 指定子の後にキーワード、識別子、または文字列が必要です: @
ここにコードがあります
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" %>