Application_BeginRequest执行了两次

时间:2014-04-10 13:29:56

标签: c#-4.0 .net-4.0 dotnetnuke global-asax url-redirection

在我的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的负载。请帮忙。

0 个答案:

没有答案