将所有请求映射到一种方法

发布于 2024-12-06 11:45:51 字数 1191 浏览 1 评论 0原文

我想将来自 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

薄荷→糖丶微凉 2024-12-13 11:45:51

好的,我已经找到问题出在哪里了。在配置文件中,path="." 应该是 path="*"

Ok, I have found where is the problem. In config file instead of path="." should be path="*"

无边思念无边月 2024-12-13 11:45:51

例如,如果您想重新映射诸如 *.aspx 之类的路径,则需要清除从计算机配置继承的现有处理程序。

<handlers>
  <clear />
  <add name="Processor" verb="*" path="*" 
                             type="WebClient.Processor,WebClient" />
</handlers>

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>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文