By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
448,572 Members | 1,225 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 448,572 IT Pros & Developers. It's quick & easy.

Automatic Redirection from login page to previous page

pentahari
P: 60
Redirect to login page if session("UserName") is expired when the page useraccount.aspx load event


My useraccount.aspx code :

Expand|Select|Wrap|Line Numbers
  1. If Session("UserName") Is Nothing Then
  2.     Response.Redirect("../login/login.aspx")
  3. End If
The above code works correctly. but my question is the user enter the correct username and password in the login.aspx page . it will automatically redirect to previous page (useraccount.aspx; useraccount.aspx is the sample name of the page but i have used the session redirect coding to many pages in my project).
Jul 2 '08 #1
Share this Question
Share on Google+
8 Replies


Curtis Rutland
Expert 2.5K+
P: 3,256
Did you make sure to set Session("UserName") equal to some value after a successful login? If you forgot to set it, its value would still be Nothing.
Jul 2 '08 #2

pentahari
P: 60
Did you make sure to set Session("UserName") equal to some value after a successful login? If you forgot to set it, its value would still be Nothing.
Sure. I have assign the value to session variable.
Jul 2 '08 #3

P: 84
Redirect to login page if session("UserName") is expired when the page useraccount.aspx load event


My useraccount.aspx code :

Expand|Select|Wrap|Line Numbers
  1. If Session("UserName") Is Nothing Then
  2.     Response.Redirect("../login/login.aspx")
  3. End If
The above code works correctly. but my question is the user enter the correct username and password in the login.aspx page . it will automatically redirect to previous page (useraccount.aspx; useraccount.aspx is the sample name of the page but i have used the session redirect coding to many pages in my project).
You can try to lock the login by directory. For this you will need to modify your web.config to specify which folder is login restricted and what url is the login page. Once you have done this, normally the redirect is handled by IIS which I would recommend.


Another option for you is to add the url from which you are directing to the login url as a variable in the url / in a session. On successful login, redirect to that variable url if availlable otherwise the default page. Though I would recommend using the first method!
Jul 2 '08 #4

kenobewan
Expert 2.5K+
P: 4,871
Even easier is to use membership class of .net 2.0. HTH.
Jul 2 '08 #5

pentahari
P: 60
Thanks for yours post.

I have solved the problems by store the current page URL to session variable when checking the session expiry, and it call back from after successful login.
Jul 2 '08 #6

Curtis Rutland
Expert 2.5K+
P: 3,256
Thanks for yours post.

I have solved the problems by store the current page URL to session variable when checking the session expiry, and it call back from after successful login.
I see that I was misunderstanding your problem. Sorry about that. Glad you solved it.
Jul 2 '08 #7

pentahari
P: 60
I have found the easy way to this problem.

pass the current URL as query string to login page when the check session expiry operation.
Jul 3 '08 #8

P: 84
I have found the easy way to this problem.

pass the current URL as query string to login page when the check session expiry operation.
Glad to hear that it worked out for you. Though for future you might want to check my other option as it is url encodes the url for you automatically!
Jul 3 '08 #9

Post your reply

Sign in to post your reply or Sign up for a free account.