让Response.Redirect页面重定向更有效率

用 Redirect 方法可将浏览器重定向到另一个 URL,而不是将内容发送给用户。 这里有一篇文章介绍使用Redirect《Using Response.Redirect Effectively》 ,文章详细的讨论了Response.Redirect ,给出了一段代码:

public static class HttpResponseExtensions
{
public static void RedirectUser(this HttpResponse response, string url)
{
if (response.IsRequestBeingRedirected)
return;
response.Redirect(url, false);
var context = HttpContext.Current;
if (context != null)
         {
context.ApplicationInstance.CompleteRequest();
}
}
}
另外ASP.NET 4 增加了一个RedirectPermanent方法,该方法同样是重定向,但生成的HTTP响应状态不是上边所演示的302,而是301(永久跳转),301 是对搜索引擎最友好的重定向方式。你有个网站http://www.cnblogs.com ,当人们访问http://www.cnblogs.com 这个URL时,你就把他们重定向到http://www.cnblogs.com/shanyou/,那么当搜索引擎爬到http:www.cnblogs.com这个网址时,如果它不能很好地跟随重定向,则它将认为http://www.cnblogs.com页面时没有内容的,所以这个页面的排名将会非常靠后。 如果我们把一个地址采用301 跳转方式跳转的话,搜索引擎会把老地址的PageRank等信息带到新地址,同时在搜索引擎索引库中彻底废弃掉原先的老地址。

.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, "Courier New", courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }

上一篇:C# 不添加WEB引用调用WSDL接口


下一篇:C#中WebService的创建、部署和调用的简单实例