Reputation: 271
I am building a website with VS2013 RC and MVC 5 and am trying to use formsAuthentification without registering permanent users on my site.
I'm posting to my company's api to authenticate user's names and passwords. When this comes back successfully, I want to issue an authorization cookie with:
System.Web.Security.FormsAuthentication.SetAuthCookie(username, false);
I see the .ASPXAUTH=... cookie after this is called.
But, I can not get into the @if(User.Identity.IsAuthenticated) or alternatively @if(Request.IsAuthenticated) block on the template's _LoginPartial.cshtml page.
This technique did work for me in MVC 4 and I am trying to bend it to fit MVC 5's OWIN authentication.
Upvotes: 4
Views: 10784
Reputation: 1127
I tried all the above solutions ,but the thing that solves my problem was commenting this in web.config
<modules>
<remove name="FormsAuthentication"/>
</modules>
Upvotes: 1
Reputation: 479
Those who still have this issue and have tried all above approaches I do recommend try add to the Web.Config file in the section authentication forms cookieless="UseCookies". In my case it worked fine.
<system.web>
<authentication mode="Forms">
<forms loginUrl="~/Account/Login" cookieless="UseCookies" timeout="2880" />
</authentication>
...
</system.web>
Upvotes: 0
Reputation: 19843
If you don't want to fight against MVC5 new authentication mode (OWIN) you can find your answer in this link
http://www.khalidabuhakmeh.com/asp-net-mvc-5-authentication-breakdown-part-deux#disqus_thread
Upvotes: 2
Reputation: 271
I needed to enable forms authentication in the web.config
<system.web>
<authentication mode="Forms">
<forms loginUrl="~/Account/Login" timeout="2880" />
</authentication>
...
</system.web>
Upvotes: 17