0
我想在我刚刚使用WebMatrix构建的现有网站上设置简单成员资格。我已经按照本教程中的步骤操作 - http://www.mikepope.com/blog/DisplayBlog.aspx?permalink=2240Webmatrix WebSecurity未验证
我遇到的问题是,如果我打电话给WebSecurity.IsAuthenticated,它似乎永远不会实际登录。登录中的代码将尽可能地重定向人们会认为用户已被认证。这里是我的登录代码:
@{
var username = "";
var password = "";
var errorMessage = "";
if(IsPost){
username = Request["username"];
password = Request["password"];
if(WebSecurity.Login(username,password,true)){
Response.Redirect("~/admin/modules/pages");
}
else
{
errorMessage = "Login was not successful.";
}
}
}
当用户被重定向到/管理/模块/页的位置有一段简单的代码来显示用户名如果登录,但它从来不会。它只是说,你还没有登录。这里的代码:
@if(WebSecurity.IsAuthenticated)
{
<h2>Hello @WebSecurity.CurrentUserName, you are logged in | <a href="/admin/logout">Log out</a></h2>
}
else
{
<h2>You are not logged in | <a href="/admin/login">Log in</a></h2>
}
希望有人可以提供帮助。提前致谢。