【问题标题】:How to hide the url of error pages?如何隐藏错误页面的url?
【发布时间】:2014-06-18 07:34:56
【问题描述】:

每当我的应用程序出现错误时,服务器会将其重定向到错误页面,但该页面的 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>

有人对此有什么建议吗?

【问题讨论】:

标签: c# asp.net web-config


【解决方案1】:

在 Form_Load 中使用以下代码

Exception exception = Server.GetLastError();

            if (exception == null)
            {
                //redirect
            }

当没有发生异常时,您可以将用户重定向到未找到的页面

限制用户直接访问错误页面是一种简单的方法。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-01-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-05-26
    • 2012-08-28
    • 1970-01-01
    相关资源
    最近更新 更多