我已经设置与窗体身份验证一个简单的登录,在一个ASP.NET MVC应用程序在我的本地正常工作我应该用什么来代替身份验证的用户在我的.cshtml与窗体身份验证
我可以访问登录表单在实时应用中发布它。
但是,当我将网站发布到Web上的实时应用程序时,表单身份验证不起作用。我究竟做错了什么?
这里是我的代码:
<system.web>
<authentication mode="Forms">
<forms loginUrl="~/Home/Login" timeout="30" />
</authentication>
</system.web>
控制器:
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>
}
为什么这不适用于实时应用程序?
UPDATE:
我现在已经foud,它并没有在本地主机上的工作也。问题是@if (User.Identity.IsAuthenticated)
我应该在我的.cshtml文件中使用经过身份验证的用户身份?
这是什么意思,它不工作。你观察到了什么差异?让其他人通过扩大你的答案和必要的细节来帮助你。 –
@WiktorZychla我已更新我的问题 – user3228992