ASP.NET Url重写和构造页面链接 [英] ASP.NET UrlRewriting and Constructing Page Links
问题描述
所以这篇文章讨论了如何在ASP.NET应用程序中实际实现URL重写以获取友好的网址".效果很好,非常适合将用户发送到特定页面,但是没有人知道使用参考工具之一在代码内创建友好" URL的好的解决方案吗?
So this post talked about how to actually implement url rewriting in an ASP.NET application to get "friendly urls". That works perfect and it is great for sending a user to a specific page, but does anyone know of a good solution for creating "Friendly" URLs inside your code when using one of the tools referenced?
例如,当存在重写规则时,将asp.net控件内的链接列出为〜/mypage.aspx?product = 12会成为问题,因为您将以两种不同的方式链接到内容.
For example listing a link inside of an asp.net control as ~/mypage.aspx?product=12 when a rewrite rule exists would be an issue as then you are linking to content in two different ways.
我熟悉使用DotNetNuke和FriendlyUrl的方法,其中有一个"NavigateUrl"方法可以从重写器获取友好的Url代码,但是我没有找到如何使用UrlRewriting.net或其他解决方案.
I'm familiar with using DotNetNuke and FriendlyUrl's where there is a "NavigateUrl" method that will get the friendly Url code from the re-writer but I'm not finding examples of how to do this with UrlRewriting.net or the other solutions out there.
理想情况下,我希望能够得到这样的东西.
Ideally I'd like to be able to get something like this.
string friendlyUrl = GetFriendlyUrl("~/MyUnfriendlyPage.aspx?myid=13");
编辑:我正在寻找一种通用的解决方案,而不是我必须为网站中的每个页面实施的解决方案,而是可能与相反方向的规则相匹配的解决方案.
I am looking for a generic solution, not something that I have to implement for every page in my site, but potentially something that can match against the rules in the opposite direction.
推荐答案
Routing is a different from rewriting. Implementing this technique does require minor changes to your pages (namely, any code accessing querystring parameters will need to be modified), but it allows you to generate links based on the routes you define. It's used by ASP.NET MVC, but can be employed in any ASP.NET application.
路由是.Net 3.5 SP1的一部分
Routing is part of .Net 3.5 SP1
这篇关于ASP.NET Url重写和构造页面链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!