动态URL重写查询字符串

问题描述:

您好,请帮我这个问题。

hello please help me for this question

我有以下URL - > www.sample.com/news.aspx?id=45

i have the following url --> www.sample.com/news.aspx?id=45

我想通过ID的查询字符串news.aspx并展示了这一消息,但由于URL重写的网址更改为这个 - > www.sample.com/news/my-news-45/

i want pass "id" in the query string to news.aspx and show this news, but due to url rewriting the url is changed to this --> www.sample.com/news/my-news-45/

如何从查询字符串中提取身份证?

How to extract "id" from the query string?

感谢名单对您有所帮助。

Thanx for your help

您可以手动完成URL重写但是手工编写code可能是乏味且容易出错的缺点。而不是自己做的,我建议使用在网络上免费提供的已建成的HttpModules之一,为您执行这项工作。

you can manually done URL rewriting but The downside of manually writing code can be tedious and error prone. Rather than do it yourself, I'd recommend using one of the already built HttpModules available on the web for free to perform this work for you.

下面一些免费的,你可以下载和使用的今天:

Here a few free ones that you can download and use today:

http://urlrewriter.net/
http://www.urlrewriting.net/149/en/home.html

http://urlrewriter.net/ http://www.urlrewriting.net/149/en/home.html

<?xml version="1.0"?>

<configuration>

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

  <system.web>

    <httpModules>
      <add name="UrlRewriter" type="Intelligencia.UrlRewriter.RewriterHttpModule, Intelligencia.UrlRewriter"/>
    </httpModules>

  </system.web>

  <rewriter>
    <rewrite url="~/products/books.aspx" to="~/products.aspx?category=books" />
    <rewrite url="~/products/CDs.aspx" to="~/products.aspx?category=CDs" />
    <rewrite url="~/products/DVDs.aspx" to="~/products.aspx?category=DVDs" />
  </rewriter>  

</configuration>  

该URL的HttpModule上面rewriters也增加了常规的前pression和URL模式匹配(为避免你不必硬code每一个URL在你的web.config文件)的支持。因此,而不是硬编码的类别列表,你可以重新编写类似下面的规则来从URL动态拉类别的/products/[category].aspx组合:

The HttpModule URL rewriters above also add support for regular expression and URL pattern matching (to avoid you having to hard-code every URL in your web.config file). So instead of hard-coding the category list, you could re-write the rules like below to dynamically pull the category from the URL for any "/products/[category].aspx" combination:

  <rewriter>
    <rewrite url="~/products/(.+).aspx" to="~/products.aspx?category=$1" />
  </rewriter>  

完整参考可以在此临客中找到

the complete reference can be found on this linke

http://weblogs.asp.net/scottgu/archive/2007/02/26/tip-trick-url-rewriting-with-asp-net.aspx