System.ApplicationException:当我调用以下函数时,无法在页面回调中调用 Response.Redirect 错误

[ad_1]

当我调用以下方法时,有时会出现 Response.Redirect 无法在页面回调中调用错误。请指出我错在哪里。

C#
private void GetResult()
 {
     SessionWebsitecl.CheckWebsiteSession();
     m_sTheme = SessionWebsitecl.GetLoggedInWebsite().WebsiteTheme;
     string sUrl = Stringcl.GetValue(Request.ServerVariables[StringConstantcl.HTTP_X_REWRITE_URL]);
     if (Page.IsPostBack)
     {
         if (Request.UrlReferrer != null)
         {
             sUrl = Stringcl.GetValue(Request.UrlReferrer.AbsolutePath);
         }
     }
     if (sUrl.Contains('?'))
     {
         sUrl = sUrl.Substring(0, sUrl.IndexOf('?'));
     }
     HttpModulecl oHttpModulecl = new HttpModulecl();
     string sRedirectedUrl = oHttpModulecl.GetTargetURL(sUrl, sUrl);
     if (sRedirectedUrl != "")
     {
         string sQueryString = Request.Url.Query;
         if (sQueryString != "")
         {
             sRedirectedUrl = sRedirectedUrl + sQueryString;
         }
         Response.Status = "301 Moved Permanently";
         Response.AddHeader("Location", sRedirectedUrl);
         Response.End();
     }
     WebsitePagecl.enmPageType ePageType = WebsitePagecl.enmPageType.DynamicLandingPage;
     WebsitePagecl oWebsitePage = new WebsitePagecl();
     int iPageId = oWebsitePage.GetPageId(sUrl, ePageType);
     if (iPageId != 0)
     {
         if (ePageType != WebsitePagecl.enmPageType.None)
         {
             GeneratePageContent(ePageType, iPageId);
             this.RenderSEODetail(ePageType, iPageId);
         }
     }
     else
     {
         Response.Redirect("/include/information/error_404.aspx");
     }
     string sParameter = Request["__EVENTARGUMENT"]; // this parameter contains url to redirect along with the search prefernce
     string sTarget = Request["__EVENTTARGET"]; // target of the event
     if (sParameter != null && sTarget == "btnSeeMoreLikeThis")
     {
         if (sParameter.Contains("#"))
         {
             int iIndex = sParameter.IndexOf("#");
             sUrl = sParameter.Substring(0, iIndex);
             sParameter = sParameter.Remove(0, iIndex + 1);
             this.SetSearch(sParameter, sUrl);
         }
     }
 }

解决方案1

你好,
尝试使用重定向命令作为

C#
Response.Redirect("your path",true);

如果仍然引发异常,则在 try、catch 中处理它。

希望能帮助到你。

[ad_2]

コメント

标题和URL已复制