Webmatrix WebSecurity not authenticating

佐手、 提交于 2019-12-10 11:48:34

问题


I am trying to setup simple membership on an existing website I've just built using WebMatrix. I've followed the steps in this tutorial - http://www.mikepope.com/blog/DisplayBlog.aspx?permalink=2240

The problem I have is that after login if I call WebSecurity.IsAuthenticated it never seems to actually be logged in. The code on the login gets as far as the redirect so one would assume the user has been authenticated. Here is my login code:

@{
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.";
    }
}
}

When the user is redirected to the /admin/modules/pages location there is a simple piece of code to show the username if logged in but it never does. It just states that you are not logged in. Here's that code:

@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>
}   

Hope someone can help. Thanks in advance.


回答1:


This is strange and shouldn't be happening. Try matching your code with the samples in WebMatrix. Also match your webconfig file with the sample's webconfig. Something must be wrong someplace.



来源:https://stackoverflow.com/questions/12481119/webmatrix-websecurity-not-authenticating

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!