asp.net - 如何在asp中将缩短的url重定向(或重写url)到长(原始)url
问题描述
我创建了一个功能,可以将长网址缩短为短网址。与 bit.ly 和 google url 缩短器 Fo 例如相同
到http://hostname/snKcxi ( http://localhost:9909/snKcxi )
我创建了一个页面,即http://localhost:9909/shrtn.aspx它应该采用 url 键值:来自http://localhost/snKcxi的 snKcxi然后将控制权转移到原始长 url 即如果我点击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
我尝试过 URL 重写,例如:
<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 错误页面!谁能帮我吗?有什么建议或改变吗??
我想做的是从短网址中获取密钥(我将根据密钥从数据库中搜索长网址)然后将其传输到长网址
解决方案
在 web.config 文件中添加了以下规则并解决了问题。
<match url="^[a-zA-Z0-9]+$" />
<action type="Rewrite" url="/shrtn.aspx?id={R:0}"/>
推荐阅读
- reactjs - 在没有第三方库的情况下克隆 React 中的嵌套状态属性?
- python - Python动画,线从移动点开始并在第二个交叉点停止
- python - Python:为什么我的模块变量会丢失它们的内容?
- c# - 内存优化:声明多个字符串变量 VS 就地使用
- php - 确定 JSON 中给出的属性是否为数组
- xaml - Xamarin 自定义面板:缺少大小类型。我需要哪些参考资料?
- ruby-on-rails - 如何在 rails 中使用 params[:search] 作为输入?
- python - 将两个日期时间对象转换为每月日期时间范围
- vue.js - 如何在 VueJS 中全局覆盖第 3 方组件的属性
- javascript - 如何使用 --outDir TypeScript compilerOptions