You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

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 defined
  • Uncaught 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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.13 20:22:23