ASP.NET Generic Handler编译错误

时间:2013-10-02 14:27:46

标签: c# asp.net

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

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

  2. 逐字逐句后预期的关键字,标识符或字符串     说明符:@

  3. 这是代码

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

1 个答案:

答案 0 :(得分:0)

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