Asp.net 我应该使用什么来代替我的.cshtml中的身份验证用户,并使用表单身份验证

Asp.net 我应该使用什么来代替我的.cshtml中的身份验证用户,并使用表单身份验证,asp.net,authentication,forms-authentication,Asp.net,Authentication,Forms Authentication,我在ASP.NET MVC应用程序中设置了一个简单的带有表单身份验证的登录,可以在本地主机上正常工作 我可以访问登录表单并在live app中发布 但是,当我将网站发布到web上的实时应用程序中时,表单身份验证不起作用。我做错了什么 这是我的密码: <system.web> <authentication mode="Forms"> <forms loginUrl="~/Home/Login" timeout="30" /&g

我在ASP.NET MVC应用程序中设置了一个简单的带有表单身份验证的登录,可以在本地主机上正常工作

我可以访问登录表单并在live app中发布

但是,当我将网站发布到web上的实时应用程序中时,表单身份验证不起作用。我做错了什么

这是我的密码:

<system.web>
        <authentication mode="Forms">
            <forms loginUrl="~/Home/Login" timeout="30" />
        </authentication>
</system.web>
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>
        }
@if(User.Identity.IsAuthenticated)
{
}
为什么这在实时应用程序中不起作用

更新:


我发现它在本地主机上也不起作用。问题是
@if(User.Identity.IsAuthenticated)

在我的.cshtml文件中,我应该使用什么来代替已验证的用户?

可能是一个愚蠢的答案,但您的web.release.config中确实有密钥,而不仅仅是web.debug.config


如果您在尝试登录时返回500或400个错误,您能在浏览器开发工具中看到吗?也可能是路由问题

这意味着什么?它不起作用了。你观察到了什么不同?让其他人帮助你,用必要的细节扩展你的答案。@WiktorZychla我已经更新了我的问题,因为它在localhost上也不起作用。问题是
@if(User.Identity.IsAuthenticated)
我应该使用什么来代替我的.cshtml文件中经过身份验证的用户?这是因为您使用javascript登录。FormsAuthentication.SetAuthCookie会在响应中发送cookie,但浏览器在您重新加载站点之前不会设置cookie。你在这里有一些相关信息:我重新加载网站<代码>返回重定向到操作(“索引”)@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> }