我想将http://www.mydomain.com/ {任何网址路径}的所有请求映射到一个方法,并决定使用下面的代码。不幸的是我得到404,为什么?
配置文件
<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>
代码
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
}
}
答案 0 :(得分:0)
好的,我发现了问题所在。在配置文件而不是path =“。”应该是path =“*”
答案 1 :(得分:0)
如果要重新映射*.aspx
之类的路径,则需要清除从机器配置继承的现有处理程序。
<handlers>
<clear />
<add name="Processor" verb="*" path="*"
type="WebClient.Processor,WebClient" />
</handlers>