Visual Studio 2010 ASP.NET 4.0 WebForms 路由在 IDE 调试模式下不起作用
您好,
我正在使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
阅读这篇文章后,我发现了我的问题:
Asp.Net System.Web.Routing 不会路由 URL,除非最后有 .aspx
我的 VS2010 解决方案包含多个项目:Web、业务层类、数据访问层类等。我的 Web 项目名为“SystemName.WebForms”。由于某些奇怪的原因,Web 项目名称中的句点会干扰 ASP.NET 4.0 的 WebForm 路由。一旦我将项目重命名为“SystemName_WebForms”,所有路由都可以正常工作。
网络项目名称中包含句点:
网络项目名称中没有句点:
有效 路线:
非常感谢@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:
WITHOUT A PERIOD IN THE WEB PROJECT NAME:
ROUTES:
Many thanks to @vincentw56 for finding and posting the answer to his question!!
MomentSurfer