WebMatrix中WebSecurity不进行身份验证 [英] Webmatrix WebSecurity not authenticating

查看:111
本文介绍了WebMatrix中WebSecurity不进行身份验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图安装简单会员现有的网站,我使用WebMatrix中刚刚建成的。我已经按照本教程中的步骤 - http://www.mikepope.com /blog/DisplayBlog.aspx?permalink=2240

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

我的问题是,登录后,如果我叫WebSecurity.IsAuthenticated它似乎永远不会实际登录。[登录code作为多远的重定向所以人们会假定用户已通过验证。这是我的登录code:

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

当用户被重定向到/管理/模块/页的位置有一个简单的一块code,以显示用户名如果​​登录,但它从来不会。它只是指出您尚未登录下面是code:

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.

推荐答案

这是奇怪的,不应该发生的事情。尝试在WebMatrix的样品符合code。同时匹配具有样本的webconfig您webconfig文件。一定出事了某个地方。

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.

这篇关于WebMatrix中WebSecurity不进行身份验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆