Ok this might be a terribly simple one but its really baffeling me...
Quick overview - I am creating a Web Application using Visual Web Developer 2008 (vb) ASP.NET 3.5
Ok, so say if I log in to the application from login.aspx as User1 and then once authenticated I am taken to default.aspx. I then navigate to another page, for arguments sake call it page1.aspx.
Now I log out as User1 and log back in as User2. Instead of being shown default.aspx as earlier I am taken back to the page that the previous user was on - page1.aspx.
How do I set what page is show once a user logs out and back in again?
Many Thanks.
![]() |
0 |
![]() |
When you logout, you could simply redirect the user to login.aspx or default.aspx, so the ReturnUrl parameter will be set to either default.aspx or not set at all.
In your forms authentication element in web.config, you can mention the defaultUrl property, which will be used when there is no ReturnUrl query string
Kumar Reddi
![]() |
0 |
![]() |
Hi Kumar,
I have added the following to the web.config file. Is this what you meant?
<!--SET FORMS AUTHENTICATION -->
<authentication mode="Forms">
<forms loginUrl="login.aspx" returnUrl="default.aspx">
</forms>
</authentication>
It appears returnUrl is unrecognized attribute.
Could you advise further?
Many Thanks.
![]() |
0 |
![]() |
returnUrl is generated by the asp.net. The typical returnUrl would be the address of the URL where the user intended to go, prior to login prompt. For example, if user typed
http://localhost/loginTest/default.aspx on a site which requires forms authentication, he would be redirected to login page with the url in the address bar as this
http://localhost/loginTest/login.aspx?ReturnUrl=%%2floginTest%2fdefault.aspx
As you can see from the above example, returnUrl was %%2floginTest%2fdefault.aspx
You can only set, defaultUrl in the web.config. This parameter will be used by the asp.net to redirect the user after authentication, if there is no returnUrl in the query string. Which can happen, if user directly navigates to the login.aspx
Go through this article, for a better understanding of how Forms Authentication work
http://msdn.microsoft.com/en-us/library/aa480476.aspx
Kumar Reddi
![]() |
0 |
![]() |
Having read about Forms Authentication I'm still having difficulties...
What I am trying to achieve is if a user logs in to the app from login.aspx as User1 and then once authenticated this user is taken to default.aspx. The user then navigates to another page within the app, for example page1.aspx.
Now User1 logs out and a new different users logs in as User2. Instead of being shown default.aspx (as earlier with User1) User2 is taken back to the page that the previous user was on - page1.aspx.
This is the ReturnUrl that is produced:
http://localhost/loginTest/login.aspx?ReturnUrl=%%2floginTest%2fpage1.aspx
Really i do not want a return ReturnUrl once a user logs out of the app.
So just the link: "http://localhost/loginTest/login.aspx"
or have it as "http://localhost/loginTest/login.aspx?ReturnUrl=%%2floginTest%2fdefault.aspx" as default.
I want the user to go to Default.aspx each time they log in - not be redirected to page the previous user was on... if you see what i mean!
I have set the following to the web.config but it still returns to the page that the previous user was on instead of to default.aspx.
<!--SET FORMS AUTHENTICATION -->
<authentication mode="Forms">
<forms loginUrl="login.aspx" DefaultUrl="default.aspx">
</forms>
</authentication>
Any suggestions??
Many Thanks.
![]() |
0 |
![]() |
That you have to set in the Logout page code
When the user clicks Logout Button, you do FormsAuthentication.Signout.. So in the same code block.. right after you killed the forms authentication and possibly Session also, using Session.Abandon(), simply redirect the user to login.aspx, or default.aspx using Response.Redirect, that way the new user always starts with default.aspx page
Kumar Reddi
![]() |
0 |
![]() |
If you are using Asp.net LoginStatus Control ... you can set LogoutAction Property:
<
asp:LoginStatus ID="LoginStatus1" runat="server" LogoutAction="RedirectToLoginPage" />
/GuruBhai
![]() |
0 |
![]() |
That worked brilliantly!!
Protected Sub LoginStatus_LoggingOut(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.LoginCancelEventArgs)
FormsAuthentication.SignOut()
Session.Abandon()
Response.Redirect("/loginTest/Login.aspx")
End Sub
Many thanks for your help Kumar!!
![]() |
0 |
![]() |
guru_sarkar:
<asp:LoginStatus ID="LoginStatus1" runat="server" LogoutAction="RedirectToLoginPage" />
That works even better!!
Thanks for all your help guys!!
Can either of you shed some light on this...
http://forums.asp.net/t/1370525.aspx
Has been up since yesterday and had no reponces as yet...
![]() |
0 |
![]() |