session
-
hi all, in my web application i made a session (Session["UserName"] = tbUserName.text) so it saves value in it if username is correct and redirect the user to mainpage.aspx. the problem is:- in login page if i copy the link of main page and paste it in address bar at the login page it redirects it without even entering any data at Username and password. i tried to check the session in main.aspx and see if empty redirect user to login which works the first time but as soon as i enter valid username and password in login the problem appear again even when i put the following at logout linkbutton (session["UserName"] = null) can anyone help!!!! thx in advance
-
hi all, in my web application i made a session (Session["UserName"] = tbUserName.text) so it saves value in it if username is correct and redirect the user to mainpage.aspx. the problem is:- in login page if i copy the link of main page and paste it in address bar at the login page it redirects it without even entering any data at Username and password. i tried to check the session in main.aspx and see if empty redirect user to login which works the first time but as soon as i enter valid username and password in login the problem appear again even when i put the following at logout linkbutton (session["UserName"] = null) can anyone help!!!! thx in advance
loading from cache,clear the cache add this on page load of all pages Response.AddHeader("Cache-control", "no-store, must-revalidate, private,no-cache"); Response.AddHeader("Pragma", "no-cache"); Response.AddHeader("Expires", "0");
-
loading from cache,clear the cache add this on page load of all pages Response.AddHeader("Cache-control", "no-store, must-revalidate, private,no-cache"); Response.AddHeader("Pragma", "no-cache"); Response.AddHeader("Expires", "0");
???!!!! what, how??
-
hi all, in my web application i made a session (Session["UserName"] = tbUserName.text) so it saves value in it if username is correct and redirect the user to mainpage.aspx. the problem is:- in login page if i copy the link of main page and paste it in address bar at the login page it redirects it without even entering any data at Username and password. i tried to check the session in main.aspx and see if empty redirect user to login which works the first time but as soon as i enter valid username and password in login the problem appear again even when i put the following at logout linkbutton (session["UserName"] = null) can anyone help!!!! thx in advance
Ideally, you should destroy Session by calling Session.Abandon() method on logout.
-
Ideally, you should destroy Session by calling Session.Abandon() method on logout.
tried but still the samething.....
-
hi all, in my web application i made a session (Session["UserName"] = tbUserName.text) so it saves value in it if username is correct and redirect the user to mainpage.aspx. the problem is:- in login page if i copy the link of main page and paste it in address bar at the login page it redirects it without even entering any data at Username and password. i tried to check the session in main.aspx and see if empty redirect user to login which works the first time but as soon as i enter valid username and password in login the problem appear again even when i put the following at logout linkbutton (session["UserName"] = null) can anyone help!!!! thx in advance
During
Logoff
you should useSession.Abandon()
to set all session variable to null and InPage_Load
you should check like thisif(Session["UserName"] ==null ) Response.Redirect("Login.aspx");
If you need to learn more about session, please read this article Exploring Session in ASP.Net[^] Let me know if you need more help :)Abhijit Jana | Codeproject MVP Web Site : abhijitjana.net Don't forget to click "Good Answer" on the post(s) that helped you.
-
hi all, in my web application i made a session (Session["UserName"] = tbUserName.text) so it saves value in it if username is correct and redirect the user to mainpage.aspx. the problem is:- in login page if i copy the link of main page and paste it in address bar at the login page it redirects it without even entering any data at Username and password. i tried to check the session in main.aspx and see if empty redirect user to login which works the first time but as soon as i enter valid username and password in login the problem appear again even when i put the following at logout linkbutton (session["UserName"] = null) can anyone help!!!! thx in advance
Let me first understand the problem here - First, you had not validated the session on the main page hence when you entered the URL the main page was displayed. So, you validated the session variable and redirected the user to Login page. Now on the login page only after you sign-in you are able to go to the main page. Now you wish to log-out the user for which you use
session["UserName"] = null;
but the main page still goes thro'. Am I correct? The problem here is that you should not usesession["UserName"] = null;
to remove the session variable. You should useSession.Remove("UserName");
HTH! -
tried but still the samething.....
Check Session Value on Page_Load. Check my Answer :)
Abhijit Jana | Codeproject MVP Web Site : abhijitjana.net Don't forget to click "Good Answer" on the post(s) that helped you.
-
tried but still the samething.....
Then the problem could be with Cache. Did you tried the above solution?
-
During
Logoff
you should useSession.Abandon()
to set all session variable to null and InPage_Load
you should check like thisif(Session["UserName"] ==null ) Response.Redirect("Login.aspx");
If you need to learn more about session, please read this article Exploring Session in ASP.Net[^] Let me know if you need more help :)Abhijit Jana | Codeproject MVP Web Site : abhijitjana.net Don't forget to click "Good Answer" on the post(s) that helped you.
dear Abhijit Jana, i did what u wrote in fact my code is exactly the same..... but no use.
-
dear Abhijit Jana, i did what u wrote in fact my code is exactly the same..... but no use.
That means Session value is not null. See what is the value of Session.
-
Let me first understand the problem here - First, you had not validated the session on the main page hence when you entered the URL the main page was displayed. So, you validated the session variable and redirected the user to Login page. Now on the login page only after you sign-in you are able to go to the main page. Now you wish to log-out the user for which you use
session["UserName"] = null;
but the main page still goes thro'. Am I correct? The problem here is that you should not usesession["UserName"] = null;
to remove the session variable. You should useSession.Remove("UserName");
HTH!ok... tried but wont work..
-
ok... tried but wont work..
1. How do you check the Session variable on the main page? If possible post the code here. 2. Does the user actually click the Logout button/link?
-
1. How do you check the Session variable on the main page? If possible post the code here. 2. Does the user actually click the Logout button/link?
1.) if (Session["UserName"] == null) { Response.Redirect("Login.aspx"); } this in main.aspx page_load 2.)sure and the code to logout is :- //Session["UserName"] = null; //Session.Abandon(); Session.Remove("UserName"); Response.Redirect("Login.aspx");
-
1.) if (Session["UserName"] == null) { Response.Redirect("Login.aspx"); } this in main.aspx page_load 2.)sure and the code to logout is :- //Session["UserName"] = null; //Session.Abandon(); Session.Remove("UserName"); Response.Redirect("Login.aspx");
Did you step thro' and check what happens in the Page_Load on the main page. Check if Session["UserName"] evaluates to null or if it returns any other value. Are you checking this with-in a IsPostBack check? Can you post the entire Page_Load code? Can you re-phrase what is happening against what is expected?
-
Did you step thro' and check what happens in the Page_Load on the main page. Check if Session["UserName"] evaluates to null or if it returns any other value. Are you checking this with-in a IsPostBack check? Can you post the entire Page_Load code? Can you re-phrase what is happening against what is expected?
thank u for your consideration but i managed to solve out the problem through emptying the buffer..
-
1.) if (Session["UserName"] == null) { Response.Redirect("Login.aspx"); } this in main.aspx page_load 2.)sure and the code to logout is :- //Session["UserName"] = null; //Session.Abandon(); Session.Remove("UserName"); Response.Redirect("Login.aspx");
Please check if session is removed properly.. Check
Session.Remove("UserName");
var session = Session["UserName"];Check what you see in the session variable. If it is null, I think the session is somewhere created. If you can see the value of session, it is indeed not clearing out properly. Are you using webdev environment. I recommend you to try this in the IIS. :)
Abhishek Sur **Don't forget to click "Good Answer" if you like this Solution.
My Latest Articles-->** Windows7 API Code Pack
Simplify Code Using NDepend
Basics of Bing Search API using .NET