Asp.net 从代码调用URLEwrite

Asp.net 从代码调用URLEwrite,asp.net,iis,iis-7,url-rewriting,seo,Asp.net,Iis,Iis 7,Url Rewriting,Seo,我有一个url作为字符串,我想调用asp.net代码(IIS7模块),该代码在进入我的应用程序的过程中重写url,并从中获取重写的url: http://webserver/nice/url/youHaveThere 到 http://webserver/app/Default.aspx?category=nice&catalog=url&pageid=youHaveThere 我想从asp.net应用程序内部调用此函数。我该怎么做?我假设您的服务器上已经安装了该模块,并且正在询问如何定义特定规

我有一个url作为字符串,我想调用asp.net代码(IIS7模块),该代码在进入我的应用程序的过程中重写url,并从中获取重写的url:

http://webserver/nice/url/youHaveThere

http://webserver/app/Default.aspx?category=nice&catalog=url&pageid=youHaveThere


我想从asp.net应用程序内部调用此函数。我该怎么做?

我假设您的服务器上已经安装了该模块,并且正在询问如何定义特定规则。在这里,您可以阅读有关创建规则的所有内容

这些规则都是通过正则表达式完成的,而不是我的特长。但这是一个格式示例:

<rewrite>
  <rules>
    <rule name="Rewrite to article.aspx">
      <match url="^article/([0-9]+)/([_0-9a-z-]+)" />
      <action type="Rewrite" url="article.aspx?id={R:1}&amp;title={R:2}" />
    </rule>
  </rules>
</rewrite>

([0-9]+)表示数字模式,([[u 0-9a-z-]+)表示文本和数字。我认为这会对你的目标起作用:

<rewrite>
  <rules>
    <rule name="Rewrite to Default.aspx">
      <match url="^article/([_0-9a-z-]+)/([_0-9a-z-]+)/([_0-9a-z-]+)" />
      <action type="Rewrite" url="app/Default.aspx?category={R:1}&catalog={R:2}&pageid={R:3}" />
    </rule>
  </rules>
</rewrite>

我假设您的服务器上已经安装了该模块,并且正在询问有关定义特定规则的问题。在这里,您可以阅读有关创建规则的所有内容

这些规则都是通过正则表达式完成的,而不是我的特长。但这是一个格式示例:

<rewrite>
  <rules>
    <rule name="Rewrite to article.aspx">
      <match url="^article/([0-9]+)/([_0-9a-z-]+)" />
      <action type="Rewrite" url="article.aspx?id={R:1}&amp;title={R:2}" />
    </rule>
  </rules>
</rewrite>

([0-9]+)表示数字模式,([[u 0-9a-z-]+)表示文本和数字。我认为这会对你的目标起作用:

<rewrite>
  <rules>
    <rule name="Rewrite to Default.aspx">
      <match url="^article/([_0-9a-z-]+)/([_0-9a-z-]+)/([_0-9a-z-]+)" />
      <action type="Rewrite" url="app/Default.aspx?category={R:1}&catalog={R:2}&pageid={R:3}" />
    </rule>
  </rules>
</rewrite>

我不认为你会称之为“重写规则”。相反,您只需使用正则表达式替换。可能是这样的:

string nice_url = "http://webserver/nice/url/youHaveThere"
string new_url = Regex.Replace(nice_url, @"/(?<category>\w+)/(?<catalog>\w+)/(?<pageid>\w+)$", "app/Default.aspx?category=${category}&catalog=${catalog}&pageid=${pageid}");
string nice\u url=”http://webserver/nice/url/youHaveThere"
字符串new_url=Regex.Replace(nice_url,@/(?\w+/(?\w+/)/(?\w+),“app/Default.aspx?category=${category}&catalog=${catalog}&pageid=${pageid}”);

我不认为你会称之为“重写规则”。相反,您只需使用正则表达式替换。可能是这样的:

string nice_url = "http://webserver/nice/url/youHaveThere"
string new_url = Regex.Replace(nice_url, @"/(?<category>\w+)/(?<catalog>\w+)/(?<pageid>\w+)$", "app/Default.aspx?category=${category}&catalog=${catalog}&pageid=${pageid}");
string nice\u url=”http://webserver/nice/url/youHaveThere"
字符串new_url=Regex.Replace(nice_url,@/(?\w+/(?\w+/)/(?\w+),“app/Default.aspx?category=${category}&catalog=${catalog}&pageid=${pageid}”);

nah,我的web.config中有许多重写规则-我想通过这些规则运行一个url字符串,并获得如果我访问了该站点,重写的url将是什么,我的web.config中有很多重写规则-我想通过这些规则运行一个url字符串,并获得如果我访问了该站点,重写的url将是什么。我已经有了规则。我想通过这些规则传递一个url,得到一个重写后的url。我知道我假设错了,你知道他们怎么说假设。如果您试图让IIS从web表单为您做一些事情,这将是一个开始:您不能在代码隐藏中单独调用模块,但它们有AJAX UpdatePanel控件。你可能会使用类似的东西来与IIS进行交互,这显然取决于很多因素。我已经有了规则。我想通过这些规则传递一个url,得到一个重写后的url。我知道我假设错了,你知道他们怎么说假设。如果您试图让IIS从web表单为您做一些事情,这将是一个开始:您不能在代码隐藏中单独调用模块,但它们有AJAX UpdatePanel控件。您可能能够使用类似的东西与IIS接口,这显然取决于许多因素。