如何在服务器中设置404自定义错误。 [英] How do I set 404 Custom Error in server.

查看:65
本文介绍了如何在服务器中设置404自定义错误。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我正在尝试在我的项目中设置自定义错误页面。我有实际的链接http:// localhost:2900 / musiccreations / Default.aspx。如果我要删除.aspx从该链接它应该向我显示404页面找不到我的自定义错误页面。我做了但它的工作只在我的本地pc.Its无法在server.Here是我使用的代码

< customErrors模式=开defaultRedirect =Error.aspx> 
< error statusCode =404redirect =404.aspx/>

< / customErrors>



请帮我解释如何设置...

解决方案

试试以下



 <? < span class =code-summarycomment> xml     version   =  1.0   >  
< configuration >
< system.web >
..现有文本..
..现有文本..
< / system.web >
< system.webServer >
< httpErrors < span class =code-keyword>>
< remove statusCode = 401 subStatusCode = - 1 / >
< remove statusCode = 403 < span class =code-attribute> subStatusCode = - 1 / >
< remove statusCode = 404 subStatusCode = - 1 / >
< span class =code-keyword>< remove statusCode = 500 subStatusCode = - 1 / >
<! - responsemode重定向时的完整网址 - >
< 错误 statusCode = 401 路径 = http ://foo.com/default.htm responseMode = 重定向 / >
<! - 当responsemode为ExecuteURL时的本地相对路径 - >
< 错误 statusCode = 403 path = / errors /403.htm\" responseMode = ExecuteURL / >
< ; 错误 statusCode < span class =code-keyword> = 404 路径 = / somedir / oops404.htm responseMode = ExecuteURL / >
< er ror statusCode = 500 path = / somedir / 500.asp responseMode = ExecuteURL / >
< / httpErrors >
< modules runAllManagedModulesForAllRequests = true / >
< / system.webServer >
< / configuration >





以上代码片段从以下链接复制



web-config-custom-httperrors [ ^ ]


请尝试如下。



 <   customErrors     mode   =  RemoteOnly    defaultRedirect   = 〜/ ErrorPages / Oops.aspx >  
< 错误 statusCode = 404 重定向 = 〜/ ErrorPages / 404.aspx / >
< / customErrors >





阅读本文了解更多信息:显示自定义错误页面


Hi,
I am trying to set Custom error page in my project.I have the actual link http://localhost:2900/musiccreations/Default.aspx.If i am deleting .aspx from that link it should show me 404 page not found my custom error page.I did but its work only on my local pc.Its not working in server.Here is the code that i used

<customErrors mode="On" defaultRedirect="Error.aspx">
            <error statusCode="404" redirect="404.aspx" />
            
        </customErrors>


please help me out how to set this ...

解决方案

Try following

<?xml version="1.0"?>
<configuration>
   <system.web>
     .. existing text ..
     .. existing text ..
   </system.web>
   <system.webServer>
      <httpErrors>
        <remove statusCode="401" subStatusCode="-1" />
        <remove statusCode="403" subStatusCode="-1" />
        <remove statusCode="404" subStatusCode="-1" />
        <remove statusCode="500" subStatusCode="-1" />
          <!-- full url when responsemode is Redirect -->
        <error statusCode="401" path="http://foo.com/default.htm" responseMode="Redirect" />
          <!-- local relative path when responsemode is ExecuteURL -->
        <error statusCode="403" path="/errors/403.htm" responseMode="ExecuteURL" />
        <error statusCode="404" path="/somedir/oops404.htm" responseMode="ExecuteURL" />
        <error statusCode="500" path="/somedir/500.asp" responseMode="ExecuteURL" />
      </httpErrors>
      <modules runAllManagedModulesForAllRequests="true"/>
   </system.webServer>
</configuration>



Above code snippet copied from following link

web-config-custom-httperrors[^]


Please try is as below.

<customErrors mode="RemoteOnly" defaultRedirect="~/ErrorPages/Oops.aspx">
    <error statusCode="404" redirect="~/ErrorPages/404.aspx" />
</customErrors>



Read this for more info : Displaying a Custom Error Page


这篇关于如何在服务器中设置404自定义错误。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆