0

我有一个通用处理程序,它根据查询字符串为 PDF 提供服务。我以前没有使用过处理程序,但是当我构建时,我得到了 2 个我找不到解决方案的奇怪错误:错误是:

  1. 命名空间不能直接包含字段或方法等成员

  2. 逐字说明符后应有关键字、标识符或字符串:@

这是代码

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" %>
4

1 回答 1

0

我想通了... ashx 文件本身被设置为编译,将其更改为内容并仅编译 cs 文件并构建..

于 2013-10-02T14:43:17.880 回答