http 处理程序在 cs 文件中不起作用,但在 ashx 文件中起作用

http handler doesn't work in cs file but works in ashx file

我正在尝试 运行 http 处理程序。我有一个随附的代码,当我将它直接放入 ashx 文件时可以使用,但是当我将它们分开并放入 cs 文件时它就不起作用,我不确定为什么。

<%@ WebHandler Language="C#"  Class="TheCityofCalgary.GSA.SharePoint.GSAClick" %>
<%@ Assembly Name="Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>

using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using System.Text.RegularExpressions;
using System.Web;
using System.Web.Configuration;
using System.Net;
using System.Runtime.Serialization;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Utilities;
using System.Configuration;

namespace TheCityofCalgary.GSA.SharePoint
{
    /// <summary>
    /// a generic http handler to redirect the ClickLog to GSALoaction that is not accessible from the public
    /// </summary>
    public class GSAClick : IHttpHandler
    {

        /// <summary>
        /// You will need to configure this handler in the web.config file of your 
        /// web and register it with IIS before being able to use it. For more information
        /// see the following link: http://go.microsoft.com/?linkid=8101007
        /// </summary>
        #region IHttpHandler Members

        private const string GSA_LOCATION_KEY = "GSALocation";

        public static StreamWriter LogSW = null;

        public bool IsReusable
        {
            // Return false in case your Managed Handler cannot be reused for another request.
            // Usually this would be false in case you have some state information preserved per request.
            get { return true; }
        }

        /// <summary>
        /// Process incoming request and redirect to GSALocation
        /// </summary>
        /// <param name="context"></param>
       public void ProcessRequest(HttpContext context)
        {

            try
            {
                WebRequest _webRequest = WebRequest.Create(gsaLocation);
                _webRequest.BeginGetResponse(new AsyncCallback(RespCallback), null);
            }
            catch (Exception ex)
            {

                Console.WriteLine("Exception GSAClick:");
                Console.WriteLine("------------------------------");
                Console.WriteLine(ex.Message);
                Console.WriteLine("Stack trace:");
                Console.WriteLine(ex.StackTrace);               
                if(!string.IsNullOrEmpty(ex.StackTrace))
                    Log("Statck Trace: "+ex.StackTrace, true, "info");

            }

        }



        #endregion

        #region Private
        /// <summary>
        /// Required for making a async call to GSALocation but not required for response
        /// </summary>
        /// <param name="ar"></param>
        private static void RespCallback(IAsyncResult ar)
        {
            //do nothing
        }
        #endregion

    }
}

并且当我分离代码并将包含的代码留在 ashx 文件中时,它不起作用:

<%@ WebHandler Language="C#"  Class="TheCityofCalgary.GSA.SharePoint.GSAClick, TheCityofCalgary.GSA.SharePoint, Version=1.0.0.0, Culture=neutral, PublicKeyToken=9cc8cc252281ce26" %>
<%@ Assembly Name="Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>

此外,每次我 运行 我的查询时,我的处理程序都不会 运行。它 运行 仅当我转到 ashx 文件并保存它然后 运行 查询时,它 运行 才是处理程序。我再次不确定为什么会这样。

任何建议将不胜感激。

提前致谢!!

在缺少的项目中添加对程序集 TheCityofCalgary.GSA.SharePoint 的引用后它起作用了。