在ASP.NET的WebForms根据路由ASP.NET开发服务器运行时,不处理非ASP扩展 [英] ASP.NET routing in WebForms does not handle non-ASP extensions when running under ASP.NET Development Server
问题描述
我的Visual Studio 2010下创建一个默认的网站。
添加了一个简单的路由那里进的Global.asax:
routes.MapPageRoute(AboutRoute,左右,〜/ About.aspx);
这说明404当我开始的 ASP.NET开发服务器并浏览到的http://本地主机:6521 /的WebSite1 /关于
但是,当我换关于
到 about.axd
(注意个.axd扩展名)很好地工作,并浏览到/WebSite1/about.axd
什么我需要在web.config中改变,使开发服务器作为工作做IIS(正确处理无扩展名的URL)的?
这说明404当我启动ASP.NET开发服务器和浏览
HTTP://本地主机:6521 /的WebSite1 /关于
块引用>我prepared样本Web应用程序,这给了我关于我们和Default.aspx的页面。
在Default.aspx页,我写了下面code ....Default.aspx.cs code
保护无效的Page_Load(对象发件人,EventArgs的发送)
{
的Response.Redirect(的Page.GetRouteUrl(AboutRoute
新{ID =Evgenyt}));
}的Global.asax.cs code
公共类全球:System.Web.HttpApplication
{
私人无效RegisterRoute(RouteCollection路线)
{
Routes.MapPageRoute(AboutRoute,大约/ {ID},〜/ About.aspx); } 无效的Application_Start(对象发件人,EventArgs的发送)
{
RegisterRoute(RouteTable.Routes);
//上的应用程序启动时运行code }
}然后我发表了code和配置它IIS。现在,当请求到达IIS,它击溃了消息ASPNET_ISAPI.DLL ISAPI扩展。 ISAPI扩展再装Default.aspx页,执行它,和它呈现的HTML返回到IIS,终于IIS然后将其发送回客户端。
合力网址
实际网址
HTTP://localhost/Demo/AboutUs.aspx
我需要什么在web.config中改变,使开发服务器工作
作为IIS做(正确处理无扩展名的URL)的?
块引用><一个href=\"http://books.google.co.in/books?id=2wg5LCKuChcC&pg=PA773&lpg=PA773&dq=Routes.MapPageRoute%20implementation%20web.config&source=bl&ots=Hjv6eHvdLG&sig=8w10ierA20ixGRaAWyFeij4lLBk&hl=en&sa=X&ei=vrtPT-LNGYnOrQen64XnDQ&sqi=2&ved=0CGAQ6AEwCA#v=onepage&q=Routes.MapPageRoute%20implementation%20web.config&f=false\"相对=nofollow> 参考 - 与
urlMapping中
,URLRouting并不需要在Web.config中的地方。它可以用code来实现。您可以使用Application_Start事件如在Glogal.asax.cs文件的code提到注册的所有路由为您的应用。要注册,您可以使用路由RouteTable
类System.Web.Routing
命名空间。I've created a default WebSite under Visual Studio 2010. Added a simple routing there into Global.asax:
routes.MapPageRoute("AboutRoute", "about", "~/About.aspx");
This shows 404 when I start ASP.NET Development Server and browse to "http://localhost:6521/WebSite1/about"
But works nicely when I change
about
toabout.axd
(notice the .axd extension) and browse to /WebSite1/about.axdWhat do I need to change in web.config to make Development Server work as IIS does (correctly handles extension-less URLs)?
解决方案This shows 404 when I start ASP.NET Development Server and browse to "http://localhost:6521/WebSite1/about"
I prepared a sample Web Application, which gave me About us and Default.aspx pages. In default.aspx page, I wrote the following code....
Default.aspx.cs Code
protected void Page_Load(object sender, EventArgs e) { Response.Redirect(Page.GetRouteUrl("AboutRoute", new { ID = "Evgenyt" })); }
Global.asax.cs Code
public class Global : System.Web.HttpApplication { private void RegisterRoute(RouteCollection Routes) { Routes.MapPageRoute("AboutRoute", "about/{ID}", "~/About.aspx"); } void Application_Start(object sender, EventArgs e) { RegisterRoute(RouteTable.Routes); // Code that runs on application startup } }
Then I published the code and configured it on IIS. Now When the Request Reaches IIS, It routed the message to the aspnet_isapi.dll ISAPI extension. ISAPI extension then loaded the default.aspx page, execute it, and return its rendered HTML to IIS, and finally IIS then sends it back to the client.
Resultant URL
http://localhost/Demo/about/Evgenyt
Actual URL
http://localhost/Demo/AboutUs.aspx
What do I need to change in web.config to make Development Server work as IIS does (correctly handles extension-less URLs)?
Reference - Unlike
URLMapping
, URLRouting does not take place in Web.config. It can be implemented using code. You can use Application_Start Event as mentioned in your code in Glogal.asax.cs file to register all routes for your application. To register a route you can useRouteTable
class inSystem.Web.Routing
namespace.这篇关于在ASP.NET的WebForms根据路由ASP.NET开发服务器运行时,不处理非ASP扩展的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!