pks
14-03-2008, 17:23
Boa tarde.
eu estou a utilizar o Forms Authentication no meu site. (codigo de um tutorial na net)
mas aquilo esta esquisito, porque antes de eu fazer login se tento aceder a pagina teste.aspx ele redireciona me para a pagina login.aspx de onde me redireciona para a pagina teste.aspx se o login tiver correcto. mas se depois faço logout e tento aceder a pagina teste.aspx, consigo acerder :s.
como consigo que ele faça mesmo o logout?
obrigado
o teste.aspx
<%@PageLanguage="VB" %>
<%@ImportNamespace="System.Web.Security" %>
<scriptlanguage="vb"runat="server">
Sub SignOut(objSender AsObject, objArgs As EventArgs)
'delete the users auth cookie and sign out
FormsAuthentication.SignOut()
'redirect the user to their referring page
Response.Redirect(Request.UrlReferrer.ToString())
EndSub
Sub Page_Load()
'verify authentication
If User.Identity.IsAuthenticated Then
'display Credential information
displayCredentials.InnerHtml = "Current User : <b>" & User.Identity.Name & "</b>" & _
"<br><br>Authentication Used : <b>" & User.Identity.AuthenticationType & "</b>"
Else
'Display Error Message
displayCredentials.InnerHtml = "Sorry, you have not been authenticated."
EndIf
EndSub
</script>
<html>
<head>
<title>Forms Authentication</title>
</head>
<bodybgcolor="#FFFFFF"text="#000000">
<spanclass="Header">Forms Based Authentication using standard method</span>
<br>
<br>
<divid="displayCredentials"runat="server"/>
<br>
<br>
<formid="Form1"runat="server">
<asp:Buttonid="cmdSignOut"text="Sign Out"runat="server"onClick="SignOut"/>
</form>
</body>
</html>
web.config
<authenticationmode="Forms">
<formsname="appNameAuth"path="/"loginUrl="login.aspx"protection="All"timeout="1">
<credentialspasswordFormat="Clear">
<username="teste"password="test"/>
<username="teste2"password="test"/>
</credentials>
</forms>
</authentication>
login.aspx
<%@PageLanguage="VB" %>
<%@ImportNamespace="System.Web.Security" %>
<scriptlanguage="VB"runat="server">
Sub ProcessLogin(objSender AsObject, objArgs As EventArgs)
If FormsAuthentication.Authenticate(txtUser.Text, txtPassword.Text) Then
FormsAuthentication.RedirectFromLoginPage(txtUser. Text, chkPersistLogin.Checked)
Else
ErrorMessage.InnerHtml = "<b>Something went wrong...</b> please re-enter your credentials..."
EndIf
EndSub
</script>
<html>
<head>
<title>Authentication Login Form</title>
</head>
<bodybgcolor="#FFFFFF"text="#000000">
<formid="Form1"runat="server">
<tablewidth="400"border="0"cellspacing="0"cellpadding="0">
<tr>
<tdwidth="80">Username : </td>
<tdwidth="10"></td>
<td><asp:TextBoxId="txtUser"width="150"runat="server"/></td>
</tr>
<tr>
<td>Password : </td>
<tdwidth="10"></td>
<td><asp:TextBoxId="txtPassword"width="150"TextMode="Password"runat="server"/></td>
</tr>
<tr>
<td></td>
<tdwidth="10"></td>
<td><asp:CheckBoxid="chkPersistLogin"runat="server"/>Remember my credentials<br>
</td>
</tr>
<tr>
<td></td>
<tdwidth="10"></td>
<td><asp:ButtonId="cmdLogin"OnClick="ProcessLogin"Text="Login"runat="server"/></td>
</tr>
</table>
<br>
<br>
<divid="ErrorMessage"runat="server"/>
</form>
</body>
</html>
eu estou a utilizar o Forms Authentication no meu site. (codigo de um tutorial na net)
mas aquilo esta esquisito, porque antes de eu fazer login se tento aceder a pagina teste.aspx ele redireciona me para a pagina login.aspx de onde me redireciona para a pagina teste.aspx se o login tiver correcto. mas se depois faço logout e tento aceder a pagina teste.aspx, consigo acerder :s.
como consigo que ele faça mesmo o logout?
obrigado
o teste.aspx
<%@PageLanguage="VB" %>
<%@ImportNamespace="System.Web.Security" %>
<scriptlanguage="vb"runat="server">
Sub SignOut(objSender AsObject, objArgs As EventArgs)
'delete the users auth cookie and sign out
FormsAuthentication.SignOut()
'redirect the user to their referring page
Response.Redirect(Request.UrlReferrer.ToString())
EndSub
Sub Page_Load()
'verify authentication
If User.Identity.IsAuthenticated Then
'display Credential information
displayCredentials.InnerHtml = "Current User : <b>" & User.Identity.Name & "</b>" & _
"<br><br>Authentication Used : <b>" & User.Identity.AuthenticationType & "</b>"
Else
'Display Error Message
displayCredentials.InnerHtml = "Sorry, you have not been authenticated."
EndIf
EndSub
</script>
<html>
<head>
<title>Forms Authentication</title>
</head>
<bodybgcolor="#FFFFFF"text="#000000">
<spanclass="Header">Forms Based Authentication using standard method</span>
<br>
<br>
<divid="displayCredentials"runat="server"/>
<br>
<br>
<formid="Form1"runat="server">
<asp:Buttonid="cmdSignOut"text="Sign Out"runat="server"onClick="SignOut"/>
</form>
</body>
</html>
web.config
<authenticationmode="Forms">
<formsname="appNameAuth"path="/"loginUrl="login.aspx"protection="All"timeout="1">
<credentialspasswordFormat="Clear">
<username="teste"password="test"/>
<username="teste2"password="test"/>
</credentials>
</forms>
</authentication>
login.aspx
<%@PageLanguage="VB" %>
<%@ImportNamespace="System.Web.Security" %>
<scriptlanguage="VB"runat="server">
Sub ProcessLogin(objSender AsObject, objArgs As EventArgs)
If FormsAuthentication.Authenticate(txtUser.Text, txtPassword.Text) Then
FormsAuthentication.RedirectFromLoginPage(txtUser. Text, chkPersistLogin.Checked)
Else
ErrorMessage.InnerHtml = "<b>Something went wrong...</b> please re-enter your credentials..."
EndIf
EndSub
</script>
<html>
<head>
<title>Authentication Login Form</title>
</head>
<bodybgcolor="#FFFFFF"text="#000000">
<formid="Form1"runat="server">
<tablewidth="400"border="0"cellspacing="0"cellpadding="0">
<tr>
<tdwidth="80">Username : </td>
<tdwidth="10"></td>
<td><asp:TextBoxId="txtUser"width="150"runat="server"/></td>
</tr>
<tr>
<td>Password : </td>
<tdwidth="10"></td>
<td><asp:TextBoxId="txtPassword"width="150"TextMode="Password"runat="server"/></td>
</tr>
<tr>
<td></td>
<tdwidth="10"></td>
<td><asp:CheckBoxid="chkPersistLogin"runat="server"/>Remember my credentials<br>
</td>
</tr>
<tr>
<td></td>
<tdwidth="10"></td>
<td><asp:ButtonId="cmdLogin"OnClick="ProcessLogin"Text="Login"runat="server"/></td>
</tr>
</table>
<br>
<br>
<divid="ErrorMessage"runat="server"/>
</form>
</body>
</html>