首页 > 解决方案 > MVC 自定义身份验证?

问题描述

我编写了一个使用自定义身份验证的小型 mvc 应用程序。应用程序中的所有操作都使用以下注释,除了 Account 控制器的登录操作:[CustomAuthorize(Roles = "User")] 这意味着每个页面都将被重定向到登录页面进行身份验证。该应用程序运行良好,除了一个小错误。在应用程序属性页面中,我将启动操作设置为当前页面。当应用程序启动时,我希望应用程序将重定向到登录页面,但它返回以下错误:

Server Error in '/' Application.
The resource cannot be found.
Description: HTTP 404. The resource you are looking for (or one of its dependencies) could have been removed, had its name changed, or is temporarily unavailable.  Please review the following URL and make sure that it is spelled correctly.

Requested URL: /

Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.17929

请帮忙!谢谢。

标签: asp.netmodel-view-controller

解决方案


检查你的路由配置文件

routes.MapRoute(
            name: "Default",
            url: "{controller}/{action}/{id}",
            defaults: new { controller = "Home", action = "Index", id = 
            UrlParameter.Optional }
        );

推荐阅读