ASP.NET Url重写和构造页面链接 [英] ASP.NET UrlRewriting and Constructing Page Links

查看:82
本文介绍了ASP.NET Url重写和构造页面链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以这篇文章讨论了如何在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.

推荐答案

请参见路由与重写不同.实施此技术确实需要对页面进行少量更改(即,将需要修改任何访问querystring参数的代码),但是它允许您根据定义的路由生成链接.它由ASP.NET MVC使用,但可以在任何ASP.NET应用程序中使用.

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆