2011-08-19 104 views
1

我有一個asp.net的web應用程序,它允許用戶登錄和註銷。當用戶登錄時(沒問題),它說歡迎用戶名,這很好。但在它旁邊還是說登錄。任何人都可以幫助我有一些財產,我需要設置登錄?謝謝你的幫助。Asp.net登錄狀態不說用戶登錄後註銷

<asp:LoginView ID="HeadLoginView" runat="server" EnableViewState="false"> 
        <AnonymousTemplate> 
         [ <a href="~/Account/Login.aspx" id="HeadLoginStatus" runat="server">Log In</a> 
         ] 
        </AnonymousTemplate> 
        <LoggedInTemplate> 
         <span class="bold">Welcome</span><span class="bold"> 
          <asp:LoginName ID="HeadLoginName" runat="server" /> 
         </span>! [ 
         <asp:LoginStatus ID="HeadLoginStatus" runat="server" LogoutAction="Redirect" LogoutText="Log Out" 
          LogoutPageUrl="~/" /> 
         ] 
        </LoggedInTemplate> 
       </asp:LoginView> 

protected void LoginUser_Authenticate(object sender, AuthenticateEventArgs e) 
    { 
     SqlHelper userLogin = new SqlHelper(); 
     TextBox User = (TextBox) LoginUser.FindControl("UserName"); 
     TextBox Password = (TextBox) LoginUser.FindControl("Password"); 
     bool results = userLogin.UserLogin(User.Text, Password.Text); 
     e.Authenticated = results; 
    } 

回答

0

您有兩個控件,其ID爲HeadLoginStatus。這是有原因的嗎?其次,你有沒有嘗試刪除EnableViewState =「false」?

編輯

嘗試更改啓動頁的頁面在根目錄下,如果它是不是已經。看看這是否有所作爲。

我似乎已經找到了問題..或取決於你如何查看它的解決方案。

我的啓動頁面設置爲子目錄中的頁面,而不是 根目錄。我將啓動頁面更改爲根目錄中的頁面( ,其中login.aspx存在),現在它按預期工作。我不認爲 它應該已經這樣做了。

+0

我沒有碰到任何視覺工作室提供的默認設置。 – user516883

+0

你可以嘗試改變我提到的兩件事,看看它是否有任何區別? –

+0

試過他們兩個,但什麼都沒有。 – user516883

-1

刪除Anynymoustemplate。從來沒有聽說過。它不應該在那裏。

<AnonymousTemplate> 
[ <a href="~/Account/Login.aspx" id="HeadLoginStatus" runat="server">Log In</a> 
] 
</AnonymousTemplate> 

編輯:抱歉,我瘋了。由於某些原因,匿名模板在登錄後仍然顯示。

+0

這需要在那裏,以便沒有登錄的用戶可以看到它。 – user516883

+0

匿名模板:http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.loginview.anonymoustemplate.aspx –

+0

這不是問題,我添加了文本來測試,看看這是否是問題,而不是。 – user516883

0

仍然不知道爲什麼它不驗證,但我發現周圍的工作,工程 當他們點擊登出(我不得不在改變標誌的說上登出loginstatus)做到這一點

if (Request.IsAuthenticated) 
     { 
      FormsAuthentication.SignOut(); 
      Session.Abandon(); 
      // clear authentication cookie 
      HttpCookie cookie1 = new HttpCookie(FormsAuthentication.FormsCookieName, ""); 
      cookie1.Expires = DateTime.Now.AddYears(-1); 
      Response.Cookies.Add(cookie1); 
      // clear session cookie (not necessary for your current problem but i would recommend you do it anyway) 
      HttpCookie cookie2 = new HttpCookie("ASP.NET_SessionId", ""); 
      cookie2.Expires = DateTime.Now.AddYears(-1); 
      Response.Cookies.Add(cookie2); 

     Response.Redirect("~/"); 
     }