..但我没有登录控制器!
我在抛出自定义错误时得到它。
我的意思是..是的。 我从一个有一个的示例项目开始我的项目,我删除了帐户控制器,它的视图,甚至任何引用“登录”的代码(甚至web.config中可能提到它的任何条目)和它出现了这个错误。
我还能在哪里检查?
更新:我使用的是Active Directory而不是登录表单。
..but I don't have a Login Controller!
I get it when I throw a custom error.
I mean.. yeah. I started my project from a sample project that had one, and I deleted the Account Controller, its view, and even any code that referred to "Login", (and even any entries in the web.config that may mention it) and it comes up with this error.
where else would I check?
Update: I am using Active Directory instead of a login form.
最满意答案
只需将这些行添加到您的Web配置文件中:
<authentication mode="Forms"> <forms loginUrl="~/home/Login" timeout="2880"></forms> </authentication>在loginUrl中输入正确的登录页面目的地,它将重定向所有标记为[授权]的请求,而不是帐户/登录。
ok. so it seems like my issue was with the fact that I am using custom [Authorize] attributes, and I didn't have a login page at all. I am using Active Directory.
According to @Lars & @Shani, apparently I need to somehow point back to one.
Unfortunately I can't as I don't have one, and it would be useless to create one. So I came up with a method that works with my situation. In my custom [Authorize] attribute, I'm returning a RedirectToRouteResult that goes to my custom Error page:
protected override void HandleUnauthorizedRequest(System.Web.Mvc.AuthorizationContext filterContext) { base.HandleUnauthorizedRequest(filterContext); if (!_authorized) { filterContext.Result = new RedirectToRouteResult(new RouteValueDictionary(new { controller = "ErrorPage", action = "Unauthorized" })); } }I'm sure there is a few different ways to do this, but this is what I'm going with this at the moment..
更多推荐
发布评论