Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/305.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/29.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
C# 如何隐藏错误页面的url?_C#_Asp.net_Web Config - Fatal编程技术网

C# 如何隐藏错误页面的url?

C# 如何隐藏错误页面的url?,c#,asp.net,web-config,C#,Asp.net,Web Config,每当我的应用程序出现错误时,服务器就会将其重定向到错误页面,但该页面的url是可见的,可以直接访问 例如,如果出现404错误,它将给出url http://www.example.com/ErrorPages/Error.aspx http://www.example.com/ErrorPages/500.aspx 我想隐藏那个页面链接。 在Web.config中,我正在执行以下操作 <customErrors mode="RemoteOnly" defaultRedirect="~/E

每当我的应用程序出现错误时,服务器就会将其重定向到错误页面,但该页面的url是可见的,可以直接访问

例如,如果出现404错误,它将给出url

http://www.example.com/ErrorPages/Error.aspx
http://www.example.com/ErrorPages/500.aspx
我想隐藏那个页面链接。 在Web.config中,我正在执行以下操作

<customErrors mode="RemoteOnly" defaultRedirect="~/ErrorsPages/Ooops.aspx">
    <error statusCode="404" redirect="~/ErrorsPages/ErrorPage.aspx"/>
    <error statusCode="401" redirect="~/ErrorsPages/401.aspx"/>
    <error statusCode="500" redirect="~/ErrorsPages/500.aspx"/>
</customErrors>


有人对此有什么建议吗?

在表单加载中使用以下代码

Exception exception = Server.GetLastError();

            if (exception == null)
            {
                //redirect
            }
当异常未发生时,您可以将用户重定向到“未找到”页面


限制用户直接访问错误页面很容易。

您想让用户不能直接访问ErrorPage.aspx吗?如果您隐藏页面url,每个人都可以访问它。@hamedkhatami ye允许用户不直接访问该页面,只需键入可能重复的路径即可