Map all request to one method [closed]
I want to map all request from http://www.mydomain.com/{any url path} to one method and decided to use code below. Unfortunately I get 404, why?
Config file
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0" />
</system.web>
<system.webServer>
<handlers>
<add name="Processor" verb="*" path="*.*"
type="WebClient.Processor,WebClient" />
</handlers>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>
</configuration>
Code
namespace WebClient
{
public class Processor : IHttpHandler
{
#region IHttpHandler Members
public void ProcessRequest(HttpContext context)
{
//Read all request here, but never hit
}
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; }
}
#endregion
}
}
Ok, I have found where is the problem. In config file instead of path="." should be path="*"
You need to clear the existing handlers inherited from machine config, if you want to remap paths like *.aspx
for instance.
<handlers>
<clear />
<add name="Processor" verb="*" path="*"
type="WebClient.Processor,WebClient" />
</handlers>
精彩评论