Visual Studio 2010 ASP.NET 4.0 WebForms 路由在 IDE 调试模式下不起作用

发布于 2024-09-29 08:06:59 字数 760 浏览 3 评论 0原文

您好,

我正在使用 Visual Studio 2010 和 ASP.NET 4.0 构建一个 WebForms 项目,该项目使用 System.Web.Routing 中的新路由功能。当我构建解决方案并从 VS.NET 的调试环境中运行它时,只有包含“.aspx”扩展名的 RouteUrl 的路由才会正确路由到 PhysicalFile。路由引擎似乎没有“检测”到对其他 URL 发出的请求进行处理。在下面的例子中,“Scenario1”显示 404,“Scenario2”工作正常。

我将非常感谢您提供的任何指导。

这是我的 global.asax 中的相关代码:

void Application_Start(object sender, EventArgs e)
{
    // Code that runs on application startup

    // Register Routes
    RegisterRoutes();
}

void RegisterRoutes()
{
    System.Web.Routing.RouteTable.Routes.MapPageRoute("Scenario1", "scenario1/{option1}", "~/About.aspx");  
    System.Web.Routing.RouteTable.Routes.MapPageRoute("Scenario2", "scenario2.aspx", "~/About.aspx");
}

非常感谢您的宝贵时间。

瞬间冲浪者

Greetings,

I am using Visual Studio 2010 and ASP.NET 4.0 to build a WebForms project that uses the new routing features in System.Web.Routing. When I build my solution and run it from within VS.NET's debugging environment only routes with RouteUrl's that include a ".aspx" extension are being properly routed to the PhysicalFile. It appears requests made to other URLs are not being "detected" by the routing engine for processing. In the case below, "Scenario1" shows a 404 and "Scenario2" works properly.

I would greatly appreciate any guidance you can provide.

Here is the relevant code in my global.asax:

void Application_Start(object sender, EventArgs e)
{
    // Code that runs on application startup

    // Register Routes
    RegisterRoutes();
}

void RegisterRoutes()
{
    System.Web.Routing.RouteTable.Routes.MapPageRoute("Scenario1", "scenario1/{option1}", "~/About.aspx");  
    System.Web.Routing.RouteTable.Routes.MapPageRoute("Scenario2", "scenario2.aspx", "~/About.aspx");
}

Thank you kindly for your time.

MomentSurfer

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

久伴你 2024-10-06 08:07:00

阅读这篇文章后,我发现了我的问题:

Asp.Net System.Web.Routing 不会路由 URL,除非最后有 .aspx

我的 VS2010 解决方案包含多个项目:Web、业务层类、数据访问层类等。我的 Web 项目名为“SystemName.WebForms”。由于某些奇怪的原因,Web 项目名称中的句点会干扰 ASP.NET 4.0 的 WebForm 路由。一旦我将项目重命名为“SystemName_WebForms”,所有路由都可以正常工作。

网络项目名称中包含句点:

  • 只有“scenario2”和“scenario4”有效

网络项目名称中没有句点:

  • 所有方案都

有效 路线:

    RouteTable.Routes.MapPageRoute("scenario1", "scenario1/{option1}", "~/About.aspx");
    RouteTable.Routes.MapPageRoute("scenario2", "scenario2.aspx", "~/About.aspx");
    RouteTable.Routes.MapPageRoute("scenario3", "scenario3", "~/About.aspx");
    RouteTable.Routes.MapPageRoute("scenario4", "scenario4.xxx", "~/About.aspx");

非常感谢@vincentw56 找到并发布了他的问题的答案!

瞬间冲浪者

I found the issue to my problem after reading this post:

Asp.Net System.Web.Routing won't route URL unless .aspx in on the end

My VS2010 solution contains several projects: web, business layer classes, data access layer classes, etc. My web project was called "SystemName.WebForms". The period in the web project name interferes with ASP.NET 4.0's WebForm's routing for some strange reason. Once I renamed my project to "SystemName_WebForms" all of the routes work correctly.

WITH A PERIOD IN THE WEB PROJECT NAME:

  • only "scenario2" and "scenario4" work

WITHOUT A PERIOD IN THE WEB PROJECT NAME:

  • all scenarios work

ROUTES:

    RouteTable.Routes.MapPageRoute("scenario1", "scenario1/{option1}", "~/About.aspx");
    RouteTable.Routes.MapPageRoute("scenario2", "scenario2.aspx", "~/About.aspx");
    RouteTable.Routes.MapPageRoute("scenario3", "scenario3", "~/About.aspx");
    RouteTable.Routes.MapPageRoute("scenario4", "scenario4.xxx", "~/About.aspx");

Many thanks to @vincentw56 for finding and posting the answer to his question!!

MomentSurfer

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文