将所有请求映射到一种方法
我想将来自 http://www.mydomain.com/{any url path} 的所有请求映射到一个方法并决定使用下面的代码。不幸的是我得到了 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
}
}
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
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
好的,我已经找到问题出在哪里了。在配置文件中,path="." 应该是 path="*"
Ok, I have found where is the problem. In config file instead of path="." should be path="*"
例如,如果您想重新映射诸如
*.aspx
之类的路径,则需要清除从计算机配置继承的现有处理程序。You need to clear the existing handlers inherited from machine config, if you want to remap paths like
*.aspx
for instance.