Setting user programmatically in ASP.NET MVC5
asp.net, asp.net-mvc, c#
Solution
Make sure form Athentication is enabled in your `web.config` file.
<system.web>
<authentication mode="Forms">
<forms loginUrl="~/Account/Login" timeout="2880" />
</authentication>
...
</system.web>
Problem
I want to log user programatically in ASP.NET MVC5. I'm setting auth cookies like this: ``` FormsAuthentication.SetAuthCookie(username, true); ``` I thouth it will be enough. But then I want to check value of Request.IsAuthenticated and it is always false. Also when I'm checking value of User.Identity.Name I'm getting empty string, not the username I passed earlier. What should I do to make this work and set this values correctly? EDIT: One more thing. I'm not using any login form, I'm passing user data (login and token) from different application.