本文整理汇总了C#中System.Web.HttpContextBase.ClearError方法的典型用法代码示例。如果您正苦于以下问题:C# HttpContextBase.ClearError方法的具体用法?C# HttpContextBase.ClearError怎么用?C# HttpContextBase.ClearError使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Web.HttpContextBase
的用法示例。
在下文中一共展示了HttpContextBase.ClearError方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ClearHttpContext
private void ClearHttpContext(HttpContextBase context, int statusCode)
{
context.Response.StatusCode = statusCode;
context.ClearError();
context.Response.Clear();
context.Response.TrySkipIisCustomErrors = true;
}
示例2: HandleError
public void HandleError(HttpContextBase context, int statusCode)
{
var currentError = context.Error;
if (currentError.IsNull()) return;
#if DEBUG
Debugger.Break();
#endif
this.LogException(currentError);
if (!context.IsCustomErrorEnabled || !UseCustomErrors(context.Request.IsLocal)) return;
var httpException = currentError as HttpException;
if (httpException != null) statusCode = httpException.GetHttpCode();
context.Response.SetStatus(statusCode);
_errorViewRenderer.Render(context, statusCode, currentError);
context.ClearError();
context.Response.TrySkipIisCustomErrors = true;
}
示例3: OnError
public override void OnError(HttpContextBase context)
{
Exception e = context.Server.GetLastError().GetBaseException();
HttpException httpException = e as HttpException;
int statusCode = (int)HttpStatusCode.InternalServerError;
if (httpException != null)
{
statusCode = httpException.GetHttpCode();
}
ILog log;
if (!Ioc.TryGet(out log))
{
log = new NullLogger();
}
if (httpException != null)
{
switch (statusCode)
{
case (int)HttpStatusCode.NotFound:
log.Warning(this, "Http Error: `{0}`, Request path: `{1}`", statusCode, context.Request.AppRelativeCurrentExecutionFilePath);
break;
default:
log.Error(this, "Http Error: `{0}`, Request path: `{1}`", statusCode, context.Request.AppRelativeCurrentExecutionFilePath);
break;
}
}
else
{
log.Error(this, "Web application error: `{0}`, Request path: `{1}`", e, context.Request.AppRelativeCurrentExecutionFilePath);
}
string redirectUrl = null;
if (context.IsCustomErrorEnabled)
{
CustomErrorsSection section = (CustomErrorsSection) ConfigurationManager.GetSection("system.web/customErrors");
if (section != null)
{
redirectUrl = section.DefaultRedirect;
if (httpException != null)
{
if (section.Errors.Count > 0)
{
CustomError item = section.Errors[statusCode.ToString()];
if (item != null)
{
redirectUrl = item.Redirect;
}
}
}
}
context.Response.Clear();
context.Response.StatusCode = statusCode;
context.Response.TrySkipIisCustomErrors = true;
context.ClearError();
if (!redirectUrl.IsNullOrEmpty())
{
//context.Response.Redirect(redirectUrl);
context.Server.Transfer(redirectUrl);
}
}
}