[英]Response.Redirect stopped working with IIS 7 rewrite rules
I have recently migrated a web site over to a new server running Windows Server 2008 and subsequently being hosted on IIS 7. 我最近将网站迁移到了运行Windows Server 2008并随后托管在IIS 7上的新服务器上。
I have implemented URL rewrite rules for pages. 我已经实现了页面的URL重写规则。 Here is an example. 这是一个例子。
<rule name="RewriteUserFriendlyURL58" stopProcessing="true">
<match url="^(shop)/(item)/([^/]+)/([^/]+)/([^/]+)/?$" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Rewrite" url="shopitem.aspx?{R:1}&{R:2}&id={R:3}&cat={R:4}&title={R:5}" />
</rule>
The URL should look something like this. 该网址应如下所示。 http://www.website.com/shop/item/10/products/table/ http://www.website.com/shop/item/10/products/table/
The page works fine except when I'm clicking on a Button and running this event. 该页面工作正常,除非单击按钮并运行此事件。
protected void btnAddToBasket_Click(object sender, EventArgs e)
{
Response.Redirect("~/shoppingbasket/");
}
The outcome of the Redirect seems to be Redirecting on itself and the URL then changes to: http://www.website.com/shop/item/10/products/table/?shop&item&id=10&cat=products&title=table 重定向的结果似乎是自身重定向,然后URL更改为: http : //www.website.com/shop/item/10/products/table/?shop&item&id=10& cat=products&title =table
Can anyone point me in the right direction? 谁能指出我正确的方向? I've done a few searches for this and I can't seem to find anything. 我已经对此进行了一些搜索,但似乎找不到任何东西。
This looks like it's actually "oh shoot, I missed it!" 看起来实际上是“哦,开枪,我错过了!” types of issues that we all have :). 我们都有的问题类型:)。
<action type="Rewrite" url="shopitem.aspx?{R:1}&{R:2}&id={R:3}&cat={R:4}&title={R:5}" />
You are specifically calling a Rewrite. 您正在专门调用重写。 Change it to Redirect and I'm sure it'll perform as you expect. 将其更改为“重定向”,我相信它会按预期运行。
It's worth noting that using a redirect in an event AND a rewrite in conjunction is probably conflicting in IIS. 值得注意的是,在事件中使用重定向和重写一起在IIS中可能会发生冲突。 You might want to choose one or the other. 您可能要选择一个。
I answered this question by using the following tutorial here . 我用下面的教程回答了这个问题在这里 。
I put the following code at the top of Page_Load event. 我将以下代码放在Page_Load事件的顶部。
if (!String.IsNullOrEmpty(Request.ServerVariables["HTTP_X_ORIGINAL_URL"]))
{
Form.Action = Request.ServerVariables["HTTP_X_ORIGINAL_URL"];
}
and the page is now working as expected. 并且页面现在按预期工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.