我正在使用 Http 处理程序来本地化应用程序中使用的 javascript 文件:
看:在 ASP.NET 中本地化 JavaScript 文件中的文本 http://madskristensen.net/post/Localize-text-in-JavaScript-files-in-ASPNET.aspx
我想使用提供的处理程序,因此我执行了以下操作:
1)在 Global.asax 中使用此代码忽略路由 - 我添加了routes.IgnoreRoute("{resource}.js.axd/{*pathInfo}");
代码行RegisterRoutes
方法,所以它看起来像这样:
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.IgnoreRoute("{resource}.js.axd/{*pathInfo}");
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
);
}
2)我已经添加了<add path="*.js.axd" verb="*" type="CamelotShiftManagement.HttpHandlers.ScriptTranslator" />
将其添加到 Views 文件夹中的 web.config 文件中,如下所示:
<system.web>
<httpHandlers>
<add path="*.js.axd" verb="*" type="CamelotShiftManagement.HttpHandlers.ScriptTranslator" />
<add path="*" verb="*" type="System.Web.HttpNotFoundHandler"/>
</httpHandlers>
然而我得到了找不到网页当我尝试访问以下 URL 时出错:
http://camelotshiftmanagement.com/Scripts/Administration/OrganizationalStructure.js.axd
我在这里做错了什么?
Progress:
Okay, so I found out an awkward mistake i made...
For some reason I thought that when adding a Handler for
*.js.axd
will find the file but actually it did not because the file was named
OrganizationalStructure.js
witout the
.axd
extension.
So that is the reason for the
404 error but now i get a different error from the server and I need your help again.
访问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.
好吧,我已经超出了我的水平......
我不明白为什么我的自定义处理程序没有被调用,而是一个静态文件调用处理程序。