IIS 7 中的 url 重写
嘿伙计们, 我正在使用 IIS7 和 urlrewrite,我想做的是不是为所有 url 编写规则,而是创建了通用规则并重定向指向 home.aspx,并且我已将 rawurl 及其目标 url 存储在数据库中在 global.asax 中,我检查 rawurl 是否存在于数据库中(如果存在),然后我将其重定向到找到的目标 url,但它不起作用,当我单击任何链接时,它只会转到主页。 这是我的 web.config urlrewrite 代码:
<rewrite>
<rules>
<rule name="index">
<match url="^(\W*)" />
<action type="Rewrite" url="home.aspx" appendQueryString="false" />
</rule>
</rules>
</rewrite>
下面是我的 global.asax 代码。
Dim connection As New SqlConnection(ConfigurationManager.ConnectionStrings("SiteSqlServer").ConnectionString)
Dim adapGetVanity As New SqlDataAdapter("select originalurl from crossarticle_vanityurl where url = '"+str.Remove(0,1)+"'", connection)
Dim dtGetVanity As New DataTable
adapGetVanity.Fill(dtGetVanity)
If dtGetVanity.Rows.Count <> 0 Then
HttpContext.Current.RewritePath(dtGetVanity.Rows(0) (0).ToString())
End If
请帮助我解决这个问题,或者建议任何可能的事情,我想摆脱这个,因为在我的应用程序中可能有任何类型的网址,所以我不能具体说明这一点...如果这不是正确的方法,请给一些建议
hey guys,
i am using IIS7 and urlrewrite, what i am trying to do is instead of writing the rule for all the url, i have created common rule and redirect pointed to home.aspx, and i have stored the rawurl and its destination url in the database and in global.asax i checking if the rawurl exists in the database if it is, then i am redirecting it to its found destination url, but its not working, when i click on any link it goes to homepage only.
here is my web.config urlrewrite code:
<rewrite>
<rules>
<rule name="index">
<match url="^(\W*)" />
<action type="Rewrite" url="home.aspx" appendQueryString="false" />
</rule>
</rules>
</rewrite>
and below is my global.asax code.
Dim connection As New SqlConnection(ConfigurationManager.ConnectionStrings("SiteSqlServer").ConnectionString)
Dim adapGetVanity As New SqlDataAdapter("select originalurl from crossarticle_vanityurl where url = '"+str.Remove(0,1)+"'", connection)
Dim dtGetVanity As New DataTable
adapGetVanity.Fill(dtGetVanity)
If dtGetVanity.Rows.Count <> 0 Then
HttpContext.Current.RewritePath(dtGetVanity.Rows(0) (0).ToString())
End If
Please help me for this, or suggest any possible things, i want to get rid or this, as in my application there could be any type of url, so i cannot be specific for this... if this is not the correct way, please give some suggestion
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论