http处理程序没有';t在cs文件中工作,但在ashx文件中工作

本文关键字:文件 工作 cs ashx 但在 程序 处理 http | 更新日期: 2023-09-27 18:26:15

我正在尝试运行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文件并保存它,然后运行查询时运行,它运行处理程序。我也不知道为什么会这样。

任何建议都将不胜感激。

提前感谢!!

http处理程序没有';t在cs文件中工作,但在ashx文件中工作

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

相关文章: