2011-02-09 75 views
0

我有一个Asp.Net网站应该有一个变量作为url中的字符串。使用url中的常量字符串使用url重写或路由

网站内容因年份而异。这个想法是今年在一个干净的方式在网址。

http://localhost/YEAR/index.aspx 

我已经在MVC中做了这个路由,但我不知道如何在asp.net中做到这一点。 我基本上只需要1条路线。所以所有的URL将像以前一样(index.aspx,...)

基本上,而不是有网站后面的EVERY ?year=2011我希望在路线中有这个值。

如何以及我该如何使用它?重写或路线?

回答

0

这里看看http://urlrewriter.net/

下载的组件,将其添加为您的项目提供参考。

在configSections元素web.config文件中添加此

<section name="rewriter" requirePermission="false" type="Intelligencia.UrlRewriter.Configuration.RewriterConfigurationSectionHandler, Intelligencia.UrlRewriter"/> 

再创建一个部分

<rewriter>  
<rewrite url="http://localhost/(.*).aspx" to="http://localhost/index.aspx?year=$1"/> 
</rewriter> 

试图让你需要这方面的http://localhost/2011.aspx

我希望这有助于内容