Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/30.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net web.config中的CustomError_Asp.net_Web Config - Fatal编程技术网

Asp.net web.config中的CustomError

Asp.net web.config中的CustomError,asp.net,web-config,Asp.net,Web Config,我想设计一个通用的错误页面,该页面通过HTTP状态错误显示不同的消息。可能吗 <customErrors mode="RemoteOnly" redirect="GenericErrorPage.htm"> 然后展示 Access Denied! 谢谢。是的,谢谢;如果可能,请尝试以下方法: <customErrors mode="On"> <error redirect="~/GenericError.aspx" statusCode="404"

我想设计一个通用的错误页面,该页面通过HTTP状态错误显示不同的消息。可能吗

<customErrors mode="RemoteOnly" redirect="GenericErrorPage.htm">
然后展示

 Access Denied!

谢谢。

是的,谢谢;如果可能,请尝试以下方法:

  <customErrors mode="On">
    <error redirect="~/GenericError.aspx" statusCode="404"/>
  </customErrors>
在一般错误页面(页面加载事件)中:

var ex=HttpContext.Current.Server.GetLastError();
this.lblMessage.Text+=“
”+ex.Message+ex.GetType().ToString(); 如果(ex是HttpException) { var nex=ex作为HttpException; this.lblMessage.Text+=“”+nex.GetHttpCode().ToString(); 开关(nex.GetHttpCode()) { 案例404: //做点酷的事 打破 案例503: //做些更酷的事 打破 违约: 打破 } }
是的,它;如果可能,请尝试以下方法:

  <customErrors mode="On">
    <error redirect="~/GenericError.aspx" statusCode="404"/>
  </customErrors>
在一般错误页面(页面加载事件)中:

var ex=HttpContext.Current.Server.GetLastError();
this.lblMessage.Text+=“
”+ex.Message+ex.GetType().ToString(); 如果(ex是HttpException) { var nex=ex作为HttpException; this.lblMessage.Text+=“”+nex.GetHttpCode().ToString(); 开关(nex.GetHttpCode()) { 案例404: //做点酷的事 打破 案例503: //做些更酷的事 打破 违约: 打破 } }
我的意思是在generalicerror.aspx中,如何自定义不同的消息?当然,我们可以有很多页。每一页对应一条消息。但是如果我只想要一页,谢谢,我应该考虑IIS 7吗?我们的服务器是2008,可能是IIS 7或更高版本。我的意思是在GenericError.aspx中如何自定义不同的消息?当然,我们可以有很多页。每一页对应一条消息。但是如果我只想要一页,谢谢,我应该考虑IIS 7吗?我们的服务器是2008,可能是IIS 7或更高版本。
  <system.webServer>
    <httpErrors existingResponse="Replace" errorMode="Custom">
      <remove statusCode="404"/>
      <error statusCode="404" path="GenericError.aspx" responseMode="Redirect"  />
    </httpErrors>
  </system.webServer>
<customErrors mode="On" defaultRedirect="~/GenericError.aspx" redirectMode="ResponseRewrite" />
    var ex = HttpContext.Current.Server.GetLastError();
    this.lblMessage.Text += "<br/>" + ex.Message + ex.GetType().ToString();

    if (ex is HttpException)
    {
        var nex = ex as HttpException;
        this.lblMessage.Text += " " + nex.GetHttpCode().ToString();

        switch (nex.GetHttpCode())
        {
            case 404:
                // do somehting cool
                break;
            case 503:
                // do somehting even cooler
                break;
            default:
                break;
        }
    }