【问题标题】:MVC - Redirect to specific page when trying to acess invalid urlMVC - 尝试访问无效网址时重定向到特定页面
【发布时间】:2016-02-02 02:09:31
【问题描述】:

如果用户尝试访问无效的 url,有没有办法重定向到特定页面? 示例:如果用户尝试访问“http://localhost/InvalidControllerName”,则重定向到“http://localhost/Home”。

【问题讨论】:

标签: c# .net asp.net-mvc


【解决方案1】:

添加带有 404 错误信息的 ErrorControllers 或静态页面。

修改您的 web.config(如果是控制器)。

<customErrors mode="On" >
       <error statusCode="404" redirect="~/Errors/Error404" />
</customErrors>   

或者在静态页面的情况下

<customErrors mode="On" >
       <error statusCode="404" redirect="~/Static404.html" />
</customErrors>  

这将处理错过的路线和错过的动作。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-11-08
    • 2021-04-17
    • 1970-01-01
    • 2020-05-22
    • 2014-09-18
    • 1970-01-01
    • 2023-03-12
    相关资源
    最近更新 更多