views:

210

answers:

1

Well, the title is pretty much the whole question. I'd like to be able to clear the WebBrowser controls history on every Navigate - to prevent my users from going back to a previous page. i already disabled the right click menu so they don't have access to the "Back" option, but they could still hit Backspace to go back in history. blocking the backspace key pres would cause problems when a user is legitimately using it to delete characters in web forms and such, so i figure just clearing out the history each time i navigate would completely solve the problem

EDIT: alternatively, if there is a way to detect if the Backspace key is currently pressed, i can add a check inside my handler on Navigating and cancel the event if the key is down. Too bad .NET 2.0 doesn't have the Keyboard class :(

+1  A: 

It might be easier and more robust to use the Navigating event to cancel a page navigation you don't want to allow.

Brian Ensink
in my specific case, this won't work because i want to allow my code to navigate to a specific page, i just don't want the user to navigate to that page by going "back" in history. if i block the URL, then i can no longer navigate to it in my code.
Brien W.
unless i can find a way to detect if the Backspace button is currently pressed when i'm inside my Navigating handler
Brien W.
You can easily keep track of page navigations initiated by your code and allow only those. You are attempting to block page navigation by blocking user input instead of using the event designed exactly for this purpose! You can never be sure you have blocked all the user input mechanisms. The context menu and the backspace is not enough. Alt+left arrow also works. What other user inputs are you missing? What if Microsoft adds a new one to the browser control?The Navigating event was designed for this.
Brian Ensink
It is very easy to detect if the Navigating is yours or the users... just set a flag when you call Navigate and clear it in Navigated.
Sheng Jiang 蒋晟
ah, setting a flag sounds like it will solve my problem perfectly. now i feel embarrassed that i didn't think of that in the first place!
Brien W.