hi,
i have a problem regarding signin/signout.What happens
i have a page called list view and on the top we are showing signin/signout.If user signin, then it is showing signout on to the top which is correct, but when we click signout it is going to login.aspx.When we click on to the browser's back button it again shows signout instead of signin as user is signout which is incorrect.
pls help me out.
Loading
nitin yadavPosted Jul 2, 2011, 2:13 AM
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.Cache.SetAllowResponseInBrowserHistory(false);
Andrew FensterPosted Jun 24, 2011, 3:29 PM
When user login then take value in session but when user logout then remove session but when he/she again on listview page then check there session is not null if null then show there nis link display/visible true on Listview page.
That won't work most of the time. In most browsers, when you come to a page by hitting the back button, the browser doesn't run the Javascript or do a postback. So it doesn't matter whether you use Sandeep's code or anyone else's code. If there's no postback, the code isn't going to run.
Andrew FensterPosted Jun 24, 2011, 3:21 PM
Your browser caches the web pages it views. This makes everything faster. When a page loads, the browser only downloads and updates the items that have changed. The rest comes from the browser's cache. The problem with this is that, even after the user has logged out, the browser still has your pages cached, including the ViewState. So the user can hit the back button or history and view the old pages. He can also look in the temporary internet files folder and see things.
Furthermore, in many browsers, when you hit the back button, the browser simply reloads the prior page from its cache. It doesn't execute the Javascript and it doesn't do a postback. So it doesn't matter what your code looks like. It doesn't matter what Javascript you put on the page. The user can hit the back button and view the old page, just like it was when he left it.
That's what you're seeing. The page said Logout before. You redirected to a different page. When they hit the back button, it should look the same as before, with Logout displayed.
You can't stop your user from hitting the back button. The only thing you can do is prevent the browser from caching, which means there will be nothing to see when he hits the back button. The easiest way to do this is to add this to each page in the OnLoad( ):
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.Cache.SetAllowResponseInBrowserHistory(false);
Your performance will be slower because the browser won't cache your page. It will reload everything on every post back. But it will prevent the user from viewing the last page by hitting the back button. He'll get a message that the page has expired.
It's a tradeoff. Your performance will be slower, but the user won't be able to navigate backwards. You'll have to decide whether it's worth it.
nitin yadavPosted Jun 24, 2011, 6:52 AM
but i have linkbutton, images etc... on to the listview page that shows and depends upon user signin/signout.what about this.
Sandeep ShekhawatPosted Jun 24, 2011, 6:40 AM
but when user logout then remove session
but when he/she again on listview page then check there session is not null if null then show there
nis link display/visible true on Listview page.
There have a link Sign in that is visible only when session is null
else link is disapper by default value of Visible of link set False
true or false check at load time in page load condition.
nitin yadavPosted Jun 24, 2011, 6:34 AM
but i dont want like this mate.
if we signout the page on listview and comeback on listview page then it will show signin.
Listview page is not in authentication and will be see if user is signout.
Sandeep ShekhawatPosted Jun 24, 2011, 6:07 AM
at page on Page load event of every page when u click back but than page call that web form pageload check session["user"]!=null
if yes then redirect on singin page.
Logout.aspx Page
All other page have :
}