I have setup a simple login with Forms Authentication that works fine on my localhost in an ASP.NET MVC app
I can access the login form an post it in live app.
But when I published the website into a live application on the web the Forms Authentication doesn't work. What am I doing wrong?
Here is my code:
<system.web>
<authentication mode="Forms">
<forms loginUrl="~/Home/Login" timeout="30" />
</authentication>
</system.web>
Controller:
public ActionResult LoginUser(string username, string password)
{
if (ConfigurationManager.AppSettings["UserName"] == username && ConfigurationManager.AppSettings["Password"] == password)
{
FormsAuthentication.SetAuthCookie(username, false);
return RedirectToAction("Index");
}
return RedirectToAction("Index");
}
Javascript:
$("body").on("click", "#loginbutton", function (e) {
$("#loginbutton").attr("href", "/loginuser?username=" + $('[user]').attr('user') + "&password=" + $('[pass]').attr('pass'));
});
.cshtml:
@if (User.Identity.IsAuthenticated)
{
<div class="row">
<div class="col-xs-12">
<a href="#uploadimage" class="md light btn-popup upload-cloud"><i class="fa fa-cloud-upload" id=""></i></a>
</div>
</div>
}
Why does this not work in a live-application?
UPDATE:
I have foud now that it doesn't work on localhost also. The problem is @if (User.Identity.IsAuthenticated)
What should I use instead to Authenticated user in my .cshtml files?