簡體   English   中英

如何注冊一個httphandler以處理IIS中的所有擴展?

[英]how to register a httphandler to handle all extensions in IIS?

我無法讓IIS 7加載我編寫的此處理程序。 我讓事情從一開始就很簡單。 我有一個Handler.cs文件,其中包含以下代碼:

public class Handler :IHttpHandler
{
    public bool IsReusable
    {
        get { return false; }
    }

    public void ProcessRequest(HttpContext context)
    {
        context.Response.Write("asdfasdf"); 
    }
}

我已將此文件放在根目錄中。

每當根目錄收到請求時,我都想執行此代碼,因此我已經建立了如下處理程序文件:

<configuration>
  <system.webServer>
    <handlers>
      <add name="Handler" verb="*" 
        path="*.*" 
        type="Handler" 
        resourceType="Unspecified" />
    </handlers>
  </system.webServer>
</configuration>

當我嘗試轉到localhost / runt(我的網站根目錄)時,IIS給我以下錯誤

Server Error in '/' Application.

Could not load type 'Handler'.

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 'Handler'.

Source Error: 

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.

Stack Trace: 


[HttpException (0x80004005): Could not load type 'Handler'.]
   System.Web.Compilation.BuildManager.GetType(String typeName, Boolean throwOnError, Boolean ignoreCase) +11247344
   System.Web.Configuration.HandlerFactoryCache.GetHandlerType(String type) +23
   System.Web.Configuration.HandlerFactoryCache..ctor(String type) +25
   System.Web.HttpApplication.GetFactory(String type) +91
   System.Web.MaterializeHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +338
   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +263

Version Information: Microsoft .NET Framework Version:2.0.50727.5466; ASP.NET Version:2.0.50727.5459

嘗試將類型設置為完全限定的名稱。

您可以通過Web應用程序的屬性找到默認名稱空間。

<configuration>
  <system.webServer>
    <handlers>
      <add name="Handler" verb="*" 
        path="*.*" 
        type="DefaultNamspaceFromProperties.ClassNamespace.Handler" 
        resourceType="Unspecified" />
    </handlers>
  </system.webServer>
</configuration>

我懷疑使用.NET Framework為所有內容創建默認處理程序會帶來一些安全風險,因此您可能應該做進一步的閱讀/咨詢,以確保不會對站點的安全性造成不利影響。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM