asp.net-mvcloggingiisihttphandler

IIS 8.5 , asp.net IHttpHandler and AppsendToLog


i have an handler, in which i try to write the data received in POST to log

context.Response.AppendToLog(result)

after few hints i got i added the next settings under handlers :

<add name="test1" verb="*" path="*.ashx"  type="test1"/>

but this causing the next error which i can't find a solution for :

Server Error in '/' Application.
   at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)
Could not load type 'test1'.
 Description: An unhandled exception occurred during the execution of the current web request. Please
        review the stack trace for more information about the error and where it originated in the code.
 Exception Details: System.Web.HttpException: Could not load type 'test1'.An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
HttpException (0x80004005): Could not load type &#39;test1&#39;.]
   System.Web.Compilation.BuildManager.GetType(String typeName, Boolean throwOnError, Boolean ignoreCase) +12495353
   System.Web.Configuration.HandlerFactoryCache.GetTypeWithAssert(String type) +47
   System.Web.Configuration.HandlerFactoryCache.GetHandlerType(String type) +18
   System.Web.Configuration.HandlerFactoryCache..ctor(String type) +27
   System.Web.HttpApplication.GetFactory(String type) +94
   System.Web.MaterializeHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +375
   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean&amp; completedSynchronously) +288
[HttpException]: Could not load type &#39;test1&#39;.
   at System.Web.Compilation.BuildManager.GetType(String typeName, Boolean throwOnError, Boolean ignoreCase)
   at System.Web.Configuration.HandlerFactoryCache.GetTypeWithAssert(String type)
   at System.Web.Configuration.HandlerFactoryCache.GetHandlerType(String type)
   at System.Web.Configuration.HandlerFactoryCache..ctor(String type)
   at System.Web.HttpApplication.MaterializeHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
   at System.Web.HttpApplication.GetFactory(String type)

which setting is missing or is wrong that causing this error?


Solution

  • We usually register the Custom HTTP handler class with the below format in the webconfig file located C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\CONFIG\

    <system.web>
        <httpHandlers>
          <add path="*.jpg" verb="*" type="MyNameSpace.MyClass, MyDllName" />
        </httpHandlers>
     </system.web>
    

    This way of making the custom handler requires us to precompile the Customhanlder.cs file.

    csc /t:library /r:System.Web.dll CustomHandler.cs
    

    Besides, the ASHX file, Generic handler is a common way to achieve your requirement. There is no need to register it before applying it.