ASP.NET Web Forms路由配置引发ScriptResource.axd错误的解决
ASP.NET Web Forms 路由配置引发ScriptResource.axd错误的解决办法
我在使用ASP.NET Web Forms开发网站时,为profile.aspx用户详情页配置了路由,希望将原URL http://localhost:56386/profile.aspx?username 改为更简洁的 http://localhost:56386/username 形式。
配置完成后,profile页面的路由功能正常,但其他页面出现异常:控制台抛出ScriptResource.axd相关错误,页面验证功能失效。具体错误信息如下:
VM83:1 Uncaught ReferenceError: WebForm_DoPostBackWithOptions is not definedUncaught SyntaxError: Unexpected token '<' (at WebResource.axd?d=...)
初始实现代码
global.asax 代码
void Application_Start(object sender, EventArgs e) { RouteConfig.RegisterRoutes(System.Web.Routing.RouteTable.Routes); }
App_Start/RouteConfig.cs 代码
using System; using System.Web; using System.Web.Routing; namespace ASP { public static class RouteConfig { public static void RegisterRoutes(RouteCollection routes) { routes.Add("Profile", new Route("{id}", new PageRouteHandler("~/profile.aspx"))); } } }
问题修复方案
在RouteConfig的路由注册方法中添加忽略.axd资源的规则,即可解决上述错误。修改后的RouteConfig代码如下:
public static void RegisterRoutes(RouteCollection routes) { routes.Ignore("{resource}.axd/{*pathInfo}"); routes.Add("Profile", new Route("{id}", new PageRouteHandler("~/profile.aspx"))); }
内容的提问来源于stack exchange,提问作者Tabassum Siddiqui
相关产品推荐
相关产品推荐

