System.ApplicationException:当我调用以下函数时,无法在Page回调错误中调用Response.Redirect [英] System.ApplicationException: Response.Redirect cannot be called in a Page callback error occurs when i call following function
本文介绍了System.ApplicationException:当我调用以下函数时,无法在Page回调错误中调用Response.Redirect的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当我调用以下方法时,无法在Page回调错误中调用Response.Redirect。请指出我错在哪里。
Response.Redirect cannot be called in a Page callback error comes sometime when i call following method.Please suggest where i am wrong.
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);
}
}
}
推荐答案
尝试使用重定向命令
Hi,
Try to use redirect command as
Response.Redirect("your path",true);
如果仍然会触发异常然后在try,catch中处理它。
希望它有所帮助。
and if still it fires exception then handle it in try,catch.
Hope it helps.
这篇关于System.ApplicationException:当我调用以下函数时,无法在Page回调错误中调用Response.Redirect的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文