简体   繁体   English

asp.net自定义错误

[英]asp.net Custom Error

I am rly confused about this. 我对此感到困惑。 I tried following all kind of tutorials but cant seem to get it working right I dont know what I am doing wrong sinse its the exact same as those vids I Have seen. 我尝试了所有类型的教程,但似乎无法使其正常工作,我不知道自己在做错什么,因为它与我所见过的那些视频完全相同。

I tried this 我试过了

web.config web.config

<customErrors mode="On" defaultRedirect="Error.aspx"/>

changing the application_error under Global.aspx.cs 更改Global.aspx.cs下的application_error

where it ends out with a respons redirect also tried server transfer but none of them leads me to my Error.aspx 它以响应重定向结束的地方也尝试了服务器传输,但是没有一个将我引向我的Error.aspx

does someone know a good simple tutorial on how to set one up? 有人知道如何设置一个很好的简单教程吗? or someone who can tell me step by step what to do? 或可以一步一步告诉我怎么做的人?

I tried following the first part of this guide sinse that is what I wanted. 我尝试遵循本指南的第一部分,这正是我想要的。

        protected void Application_Error(object sender, EventArgs e)
    {
        Exception ex = Server.GetLastError();
        Server.ClearError();
        Response.Redirect(@"~Error.aspx");
    }

but it tells me it goes into an infinite loop. 但它告诉我它进入了无限循环。

I want to send the user to a page called Error.aspx where they can see a custom error screen. 我想将用户发送到一个名为Error.aspx的页面,在该页面上他们可以看到自定义错误屏幕。

  1. Open IIS. 打开IIS。
  2. Select your website on the left side from Sites. 从“网站”左侧选择您的网站。
  3. Double click on .Net error pages. 双击.Net错误页面。
  4. Select Edit Feature setting from Action pane on the right side. 从右侧的“操作”窗格中选择“编辑功能设置”。
  5. Select On and give the name of your page which you want to display when any error occurs. 选择开,并提供发生任何错误时要显示的页面的名称。

I followed following steps and have not added anything in Global.asax and it is working fine for me. 我遵循了以下步骤,并且没有在Global.asax中添加任何内容,它对我来说很好用。 Just try this and remove code from global.asax. 只需尝试一下,然后从global.asax中删除代码即可。

The IIS prob will be the next problem xD hehe but I found the source to my loop and problem IIS概率将是xD的下一个问题,但是我找到了循环和问题的来源

I had this code inside my Error.aspx and that made it crash aka loop xD 我在Error.aspx中包含此代码,这使其崩溃又名xD循环

<asp:ContentPlaceHolder ID="head" runat="server" >
</asp:ContentPlaceHolder>
<configuration>
   <system.webServer>
      <httpErrors errorMode="DetailedLocalOnly" defaultResponseMode="File" >
         <remove statusCode="500" />
         <error statusCode="500"
            prefixLanguageFilePath="C:\Contoso\Content\errors"
            path="500.htm" />
       </httpErrors>
   </system.webServer>
</configuration>

Otherwise, follow these steps at IIS level 否则,请在IIS级别上执行以下步骤

HOW TO ADD A CUSTOM ERROR PAGE 如何添加自定义错误页面

http://www.iis.net/configreference/system.webserver/httperrors http://www.iis.net/configreference/system.webserver/httperrors

<configuration>
...

<system.web>
    <customErrors mode="RemoteOnly"
                  defaultRedirect="~/ErrorPages/Oops.aspx" />

    ...
</system.web>

Note the leading ~ for path resolution 注意前导〜用于路径解析

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM