asp.net - 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
请帮忙!谢谢。
解决方案
检查你的路由配置文件
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id =
UrlParameter.Optional }
);
推荐阅读
- javascript - Gatsby - 列表项的自定义 activeClass
- javascript - 从客户端发送 json 到后端的问题
- vue.js - Vue如何将数组复制到本地进行编辑?为什么它适用于字符串而不适用于数组?
- java - 我如何拥有自己的公钥来加密数据?
- vba - 网页抓取:xmlHTTP GET 请求不起作用
- python - 如何通过 python 访问画布颜色
- javascript - 如何将纵向图像放入带有横向图像的引导轮播?
- sql-server - JSON 解析 SQL Server
- javascript - 如何修复这个 MIME 类型错误,这是我认为的主要问题
- python - 叶热图 HTML 未在浏览器中显示