Asp.net mvc MVC 3应用程序中的自定义Http处理程序

Asp.net mvc MVC 3应用程序中的自定义Http处理程序,asp.net-mvc,localization,httphandler,handlers,staticfilehandler,Asp.net Mvc,Localization,Httphandler,Handlers,Staticfilehandler,我正在使用Http处理程序本地化应用程序中使用的javascript文件: 见: 我想使用提供的处理程序,因此我执行了以下操作: 1) 在Global.asax中忽略使用此代码的路由-我添加了routes.IgnoreRoute(“{resource}.js.axd/{*pathInfo}”)registerOutes方法的代码行,如下所示: 2) 我已将行添加到视图文件夹中的我的web.confing文件中,因此它看起来如下所示: 我做错了什么 进度: 好吧,我发现我犯了一个尴尬的错误。

我正在使用Http处理程序本地化应用程序中使用的javascript文件: 见:

我想使用提供的处理程序,因此我执行了以下操作:

1) 在Global.asax中忽略使用此代码的路由-我添加了
routes.IgnoreRoute(“{resource}.js.axd/{*pathInfo}”)
registerOutes方法的代码行,如下所示:


2) 我已将
行添加到视图文件夹中的我的web.confing文件中,因此它看起来如下所示:


我做错了什么


进度: 好吧,我发现我犯了一个尴尬的错误。。。 出于某种原因,我以为在为
*.js.axd
添加处理程序时会找到该文件,但实际上没有找到,因为该文件名为
OrganizationalStructure.js
,没有扩展名
.axd
。 这就是404错误的原因,但是现在我从服务器上得到了一个不同的错误,我再次需要您的帮助

访问
http://camelotshiftmanagement.com/Scripts/Administration/OrganizationalStructure.js.axd
这次产生了一个不同的错误:404.17请求的内容似乎是脚本,静态文件处理程序将不会提供这些内容

其他错误信息

Server Error in Application "CAMELOTSHIFTMANAGEMENT.COM"
Internet Information Services 7.5
Error Summary
HTTP Error 404.17 - Not Found
The requested content appears to be script and will not be served by the static file handler.

Detailed Error Information
Module:  "StaticFileModule"
Notification:  "ExecuteRequestHandler"
Handler:  "StaticFile"
Error Code:  "0x80070032"
Requested URL:  "http://camelotshiftmanagement.com:80/Scripts/Administration/OrganizationalStructure.js.axd"
Physical Path:  "C:\Code\CamelotShiftManagement\CamelotShiftManagement\Scripts\Administration\OrganizationalStructure.js.axd"
Logon Method:  "Anonymous"
Logon User:  "Anonymous"

Most likely causes:
The request matched a wildcard mime map. The request is mapped to the static file handler. If there were different pre-conditions, the request will map to a different handler.

Things you can try:
If you want to serve this content as a static file, add an explicit MIME map.
好吧,我在这里已经超过我的水平了。。。 我不明白为什么不调用我的自定义处理程序,而是调用静态文件处理程序。

好的。。。所以我确实修好了(我想)

有两个问题: 1.文件名具有
.js
扩展名,而不是处理程序需要的
.js.axd
。 2.我需要将处理程序注册到IIS,因为它是默认情况下不重新编码的自定义扩展。 为此,我在MVC应用程序的主
Web.Config
文件的
节点下添加了以下代码:

<handlers>
        <add name="CustomScriptHandler" path="*.js.axd" verb="*" type="CamelotShiftManagement.HttpHandlers.ScriptTranslator" />
</handlers>

还可以使用IIS管理器完成GUI过程(7): 打开网站节点-->处理程序映射-->添加脚本映射

不,服务器将启动正确的处理程序并运行代码

我唯一不确定的是,我仍然必须有一个扩展名为
.js.axd
的文件和一个扩展名为
.js
的文件,因为处理程序会查找要处理的Javascript文件,而服务器会查找一个
.js.axd
文件来启动自定义处理程序

如果有人有其他见解,一定要有

http://camelotshiftmanagement.com/Scripts/Administration/OrganizationalStructure.js.axd
Server Error in Application "CAMELOTSHIFTMANAGEMENT.COM"
Internet Information Services 7.5
Error Summary
HTTP Error 404.17 - Not Found
The requested content appears to be script and will not be served by the static file handler.

Detailed Error Information
Module:  "StaticFileModule"
Notification:  "ExecuteRequestHandler"
Handler:  "StaticFile"
Error Code:  "0x80070032"
Requested URL:  "http://camelotshiftmanagement.com:80/Scripts/Administration/OrganizationalStructure.js.axd"
Physical Path:  "C:\Code\CamelotShiftManagement\CamelotShiftManagement\Scripts\Administration\OrganizationalStructure.js.axd"
Logon Method:  "Anonymous"
Logon User:  "Anonymous"

Most likely causes:
The request matched a wildcard mime map. The request is mapped to the static file handler. If there were different pre-conditions, the request will map to a different handler.

Things you can try:
If you want to serve this content as a static file, add an explicit MIME map.
<handlers>
        <add name="CustomScriptHandler" path="*.js.axd" verb="*" type="CamelotShiftManagement.HttpHandlers.ScriptTranslator" />
</handlers>