2012-09-18 84 views
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> 
} 

希望有人可以提供幫助。提前致謝。

回答

0

這就奇怪了,不應該發生。嘗試將您的代碼與WebMatrix中的示例進行匹配。還可以將您的webconfig文件與示例的webconfig相匹配。有些地方一定是錯的。