简体   繁体   English

用动态参数重写asp.net url

[英]asp.net url rewrite with dynamic parameter

I use asp.net C# and need a to make an URL rewrite rule that maps a long URL to a short url, and keep the dynamic URL parameter (guid): 我使用asp.net C#,需要做一个URL重写规则,该规则将长URL映射到短URL,并保留动态URL参数(guid):

Example: 例:

The first URL (short) should be mapped / redirected to the long url below: 第一个网址(短网址)应映射/重定向到下面的长网址:

Short URL: 简短网址:

http://www.domain.com/campaign.aspx?guid=db7b1e74-f45a-4756-945f-33e812534c09

Long URL: 长网址:

http://www.domain.com/templates/sections/user/misc/campaign/freemember.aspx?guid=db7b1e74-f45a-4756-945f-33e812534c09

The GUID parameter is dynamic created, so I cannot hard code that in the rewrite rule. GUID参数是动态创建的,因此我无法在重写规则中对此进行硬编码。 Hope someone can help me creating this rewrite rule :) 希望有人可以帮助我创建此重写规则:)

I have not had to do this before, but maybe this will be of use to you. 我以前不必这样做,但是也许这对您有用。

https://sourceforge.net/projects/shorturl-dotnet/ https://sourceforge.net/projects/shorturl-dotnet/

I solved this: 我解决了这个问题:

<rewrite>
  <rules>
    <rule name="RewriteUrl">
      <match url="^campaign/([_0-9a-z-]+)" />
      <action type="Rewrite" url="/templates/sections/user/misc/campaign/freemember?id={R:1}" />
    </rule>
  </rules>
</rewrite>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM