在我的Global.asax
文件中,我有Application_BeginRequest
,每次加载页面时执行两次。我的代码如下:
protected void Application_BeginRequest(object sender, EventArgs e)
{
if ((rawUrl.StartsWith("/article.aspx?articleid=")) || (rawUrl.StartsWith("/article.aspx?id=")))
{
int ArticleId = int.Parse(rawUrl.Remove(0, rawUrl.IndexOf('=') + 1));
Entities.ArticleTemplate _temp = Common.CommonUtil.GetArticleTemplate(ArticleId);
HttpContext.Current.Cache["ArticleTemplate"] = _temp;
redirect301(_temp.Url);
}
else
{
// Handles all HTTP redirects.
string url = GetHTTPRedirects(rawUrl);
if (url != string.Empty)
redirect301(url);
else
{
string new_url = GetRedirectUrl(rawUrl);
if (new_url != String.Empty)
{
redirect301(new_url);
}
}
}
return;
}
我不希望Application_BeginRequest
执行两次,因为这样会对同一存储过程进行两次调用,这会增加Sql Server的负载。请帮忙。