如何在asp中重定向(或重写url)缩短的url到long(原始)url

时间:2018-05-17 07:15:53

标签: asp.net url-rewriting

我创建了一个功能,可以将长网缩短为短网址。与bit.ly和google url shortener相同 例如,

它会缩短https://www.moneycontrol.com/news/india/karnataka-election-results-2018-live-updates-missing-mlas-raise-concerns-in-congress-jds-camp-2568569.html

http://hostname/snKcxihttp://localhost:9909/snKcxi

我创建了一个页面http://localhost:9909/shrtn.aspx,它应该从网址http://localhost/snKcxi获取网址密钥值:snKcxi,然后将控制转移到原始的长网址,即如果我点击http://localhost:9909/snKcxi,它应该重定向到: https://www.moneycontrol.com/news/india/karnataka-election-results-2018-live-updates-missing-mlas-raise-concerns-in-congress-jds-camp-2568569.html

我尝试过网址重写,例如:

<rewrite>
  <rules> 
    <!-- For URL redirect-->
    <rule name="redirectRule" stopProcessing="true">
      <match url="^http://localhost:9909/$" />
      <action type="Redirect" url="http://localhost:9909/shrtn.aspx" redirectType="Found"/>
    </rule>
  </rules> 
</rewrite>

但它无法完成备受推崇的功能。当我点击http://localhost/snKcxi时,它会转到404错误页面! 谁能帮我吗?任何建议或改变??

我想做的是从短网址获取密钥(我将根据密钥从数据库中搜索长网址) 然后将其转移到长URL

1 个答案:

答案 0 :(得分:0)

在web.config文件中添加了以下规则&amp;问题解决了。

@users