开发者

clear browser back history via Asp.net-C#

Hi i want to clear history of user page after they sign ou开发者_JAVA技巧t from their page manipulations.I googled it and found some ways with cacheability,but it doesnt work fine.


One thing you might want to consider is handling the scenario more gracefully on the server-side.

To start with, I would consider an approach that instructs the browser to not cache the page. Then, on each of your pages that you would want to "secure" you could put a check (i.e., in a base class) for a cookie that needs to be present to access these pages. When the user signs out, remove the cookie.

That way, if the user hits the back button and does end up trying to navigate to one of those pages, the server will be required to serve the page again, and your check can be in place to see if they should be able to access it. If they shouldn't be able to, redirect them to whatever sort of page you are looking to - whether it is an informational page, a sign-in page, etc.

This also addresses the user "sharing URLs" that should be restricted and/or bookmarking them. We used a similar approach in a project before, and it was simple and effective. Users who should not be able to access the page without having signed in, were simply redirected to the sign-in page. Looking at the logs, most of them came in without a referring page, meaning that they likely had bookmarked the page.


You can not clean browser history. Neither by .net nor by javascript.


This is usually not a very good thing to do, because it would change the user experience by altering browser behaviour that has become second-nature to most users. I know that this kind of thing annoys the heck out of me when I come across it. The thought that goes through my mind is something along the lines of:

Why won't you let me go back?!! I have clicked the Back button - it should take me back! You let me get to that page before! Why can't I go back to it? Let me go back!

You should probably expand on why there is a need for this. I can imagine there are certain situations where you might want to do this, such as in an online exam situation or a survey. But in my experience, this kind of unusual requirement usually comes from a requirements gathering process that has not been well thought through.

In most situations such as the exam scenario mentioned above you will probably need to track the page views of the user in the Session State, or possibly a user database if you need to prevent them from returning to pages accross multiple sessions. Then you would need to check the ViewedPages state for that user and if they are trying to access a previous page, make decisions on whether to show them error messages or redirect them to where you want them to go to. This would be done in the Page_Load event usually.

This would allow you to prevent them from accessing previous pages in your site, without clearing the history of pages visited on other sites.

Also, you might like to look at the ASP.NET Wizard control. It is configurable to provide a forward-only wizard style interface, but it means that all of your code for the various views is on one page. Not bad for small wizards, but a little unwieldy for large ones.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜