简体   繁体   English

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

[英]Visual Studio 2010 ASP.NET 4.0 WebForms Routing Not Working in IDE Debug Mode

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. 我正在使用Visual Studio 2010和ASP.NET 4.0构建一个WebForms项目,该项目使用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. 当我构建解决方案并从VS.NET的调试环境中运行该解决方案时,只有带有“ .aspx”扩展名的RouteUrl的路由才被正确路由到PhysicalFile。 It appears requests made to other URLs are not being "detected" by the routing engine for processing. 似乎路由引擎未“检测到”对其他URL的请求进行处理。 In the case below, "Scenario1" shows a 404 and "Scenario2" works properly. 在以下情况下,“ Scenario1”显示404,而“ Scenario2”正常运行。

I would greatly appreciate any guidance you can provide. 我将不胜感激您可以提供的任何指导。

Here is the relevant code in my global.asax: 这是我的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 瞬间冲浪

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 除非最后输入.aspx,否则Asp.Net System.Web.Routing不会路由URL

My VS2010 solution contains several projects: web, business layer classes, data access layer classes, etc. My web project was called "SystemName.WebForms". 我的VS2010解决方案包含多个项目:Web,业务层类,数据访问层类等。我的Web项目被称为“ SystemName.WebForms”。 The period in the web project name interferes with ASP.NET 4.0's WebForm's routing for some strange reason. Web项目名称中的句点由于某些奇怪的原因而干扰了ASP.NET 4.0的WebForm的路由。 Once I renamed my project to "SystemName_WebForms" all of the routes work correctly. 将项目重命名为“ SystemName_WebForms”后,所有路由都可以正常工作。

WITH A PERIOD IN THE WEB PROJECT NAME: 在Web项目名称中带有句号:

  • only "scenario2" and "scenario4" work 仅“ scenario2”和“ scenario4”有效

WITHOUT A PERIOD IN THE WEB PROJECT NAME: Web项目名称中没有句号:

  • 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!! 非常感谢@ vincentw56找到并发布了他问题的答案!!

MomentSurfer 瞬间冲浪

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM