简体   繁体   English

ASP.NET WebForms域路由

[英]ASP.NET WebForms Domain Routing

I have seen a cool implementation of ASP.NET MVC Domain Routing. 我见过很酷的ASP.NET MVC域路由实现。
Source: http://blog.maartenballiauw.be/post/2009/05/20/ASPNET-MVC-Domain-Routing.aspx 资料来源: http//blog.maartenballiauw.be/post/2009/05/20/ASPNET-MVC-Domain-Routing.aspx

Could this be done on ASP.NET WebForms 4.0? 这可以在ASP.NET WebForms 4.0上完成吗?

Considering the fact that the Route class is not specific to MVC apps and can be easily used within the context of a plain ASP .NET WebForms project the DomainRoute class you linked to should work just fine in that context as well. 考虑到Route类不是特定于MVC应用程序并且可以在普通ASP .NET WebForms项目的上下文中轻松使用的事实,您链接到的DomainRoute类也应该在该上下文中正常工作。

Should be an easy enough venture to prove out. 应该是一个足够简单的冒险证明。

The answer to your question is yes. 你的问题的答案是肯定的。 It's actually pretty simple. 它实际上非常简单。 You could try the DomainRoute class or just write your own url rewriting module and be good to go. 您可以尝试使用DomainRoute类,或者只编写自己的url重写模块,并且可以继续使用。 But basically you would use something like this: 但基本上你会使用这样的东西:

http://www.gutgames.com/post/Url-Rewriting-in-ASPNet.aspx http://www.gutgames.com/post/Url-Rewriting-in-ASPNet.aspx

And instead of the Path, you'd use the Url property and parse it however you want. 而不是Path,您可以使用Url属性并根据需要对其进行解析。 Or you could just use an open source project like this: 或者您可以使用这样的开源项目:

http://sharedhostingsplittr.codeplex.com/ http://sharedhostingsplittr.codeplex.com/

And modify it slightly if need be. 如果需要,可以稍微修改一下。

Yes add Global.ascx file in your project and add a function in it written by me 是的,在项目中添加Global.ascx文件,并在其中添加一个函数

   public static void UrlRouting(RouteCollection RC, string RoutName, string routeUrl, string Page)
    {
        RC.MapPageRoute(RoutName, routeUrl, Page);
    }
after this inside Application_Start event on global.ascx file 
call that function like 
UrlRouting(RouteTable.Routes, "index", "Home", "~/index.aspx");

and then call it with route URL which is ~/Home '>Home Note: Don't forget to call ResolveUrl with your URL otherwise it cannot be called and your images and jquery,js paths should also have ResolveUrl like '/> otherwise this jquery will not work and images will not be displayed Hope this will help 然后用路由URL调用它~~ Home'> Home注意:不要忘记用你的URL调用ResolveUrl,否则无法调用它,你的图像和jquery,js路径也应该有ResolveUrl,如'/> jquery将无法工作,图像将不会显示希望这将有所帮助

The short answer is that yes, you can use routing in WebForms. 简短的回答是,您可以在WebForms中使用路由。 Look into the System.Web.Routing namespace. 查看System.Web.Routing命名空间。

In your Application_Start in your Global.asax you can set up routes based on text or regular expressions. 在Global.asax的Application_Start中,您可以根据文本或正则表达式设置路由。

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

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