Authentication request going to a page not specified
I try to exhaust all my own resources before coming here and bothering the community with a very specific question that is doubtless my own screw up, but I've exhausted them now.
I'm doing an MVC3 site, built mostly with Steven Sanderson's Mvc Scaffolding package from NuGet. (It's also using SQL CE EF Code First, and EricEJ's SqlCeMembership package.) Everything's going along swimmingly.
Until I add an [Authorize(Users="admin")] on some controller methods that I don't want to be publicly available开发者_运维问答.
And then I get a 404 error specifying a Request URL "/Account/Login" as not being found.
The mystifying thing is that nowhere in my site is there a request for /Account/Login. The authentication section from the web config is:
<authentication mode="Forms">
<forms loginUrl="~/Account/LogOn" timeout="2880" />
</authentication>
Note, "LogOn", not "Login". In fact, I have done a Cntl-F (Find) for the string "Login" (case insensitve, match whole word) over the Entire Solution, and can't find anything. I then went on and did a Find-In-Files over the entire disk and couldn't find anything meaningful.
I'm sure it's something stupid that I have done, because if I create a new Mvc project and add an Authorize attribute to one of the methods, it works fine, going to Account/LogOn. But I have no idea what I've done, and I'm out of ideas on how to find it.
Can somebody help me?
I found a solution. Have you tried changing/setting the loginUrl setting in the config file?
<appSettings>
<add key="loginUrl" value="~/Login.asp" />
</appSettings>
(Obviously change the path to your requirement)
Cheers, Chris
@Dave
I also had this same issue and found that I had mistakenly added the account folders log-on files to my projects root directory. After I deleted them I was able use [Authorize] on a controller that routed correctly to the LogOn page.
精彩评论