当没有.asmx扩展名时,为什么会收到HTTP 404? [英] Why do I get HTTP 404 when there's no .asmx extension?

查看:47
本文介绍了当没有.asmx扩展名时,为什么会收到HTTP 404?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试编写HTTP GET处理程序.该路径应以 http://site/processTask 开头,并具有一组URL编码的参数.我的web.config中有以下内容

I'm trying to write an HTTP GET handler. The path should start with http://site/processTask and have a set of URL-encoded parameters. I have the following in my web.config

<httpHandlers>
    <remove verb="*" path="*.asmx"/>
    <add verb="*" path="*.asmx" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
    <add verb="*" path="*_AppService.axd" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
    <add verb="GET,HEAD" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" validate="false"/>
    <add verb="GET" path="processTask*" type="MyHandler.ProcessTaskHandler, MyHandler"/>
</httpHandlers>

现在,当我在浏览器中键入URL http://mysite/processTask 时,我会收到HTTP 404,但是如果我将 add verb 行更改为以下内容:

now when I type the URL http://mysite/processTask in browser I get HTTP 404 but if I change the add verb line to the following one:

<add verb="GET" path="processTask.asmx*" type="MyHandler.ProcessTaskHandler, MyHandler"/>

并在浏览器中键入 http://mysite/ProcessTask.asmx ,处理程序已运行,我从处理程序中获得响应.

and type http://mysite/ProcessTask.asmx in browser the handler is run and I get the response from the handler.

出什么问题了?为什么仅在路径包含 .asmx 时才运行处理程序?如何更改 web.config ,以便不需要 .asmx ?

What's the problem? Why is the handler run only when the path contains .asmx? How do I change web.config so that .asmx is not required?

推荐答案

当路径只是/processTask (无扩展名)时IIS 首先无法理解它必须通过的所有内容对ASP.NET的请求(尤其是在IIS 5.1上),并且该文件不是由ASP.NET处理的,而是仅通过磁盘提供的(并且没有这样的文件,因此没有HTTP 404).

When a path is just /processTask (no extension) IIS can not understand first of all that it has to pass the request to ASP.NET especially on IIS 5.1, and the file is not being processed by ASP.NET but just served from disk (and there's no such file, hence HTTP 404).

要执行此操作,您需要将IIS设置为使用ASP.NET处理所有文件

To be able to do that you need to set IIS to process all files with ASP.NET

在IIS 5.1上,右键单击根目录,打开网站属性" |站点".主目录|配置,然后将设置从 *.aspx (或ASP.NET已经处理的任何其他扩展名)复制/粘贴到新扩展名,作为.* ,然后取消选中验证文件是否存在"复选框.

On IIS 5.1, right click on the root, open Web Site Properties | Home Directory | Configuration, and there copy/paste settings from *.aspx (or any other extension that is already handled by ASP.NET) to a new extension as .* and uncheck "Verify file exists" checkbox there. Here's a step-by-step guide for a similar problem.

这篇关于当没有.asmx扩展名时,为什么会收到HTTP 404?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆