question

EmekaOkoye-3272 avatar image
0 Votes"
EmekaOkoye-3272 asked YijingSun-MSFT commented

How do I make Asp.Net webform site not throw Server Error message?

I have a web application built with Asp.Net web-form, but the issue I am having is that, when user Logged in and later Log out, if he click the back button on browser immediately, it throws Error message as follows:

Object reference not set to an instance of an object.

So how do I position my code so that when user Log in and log out, on clicking back button on browser it will not throw Error message, instead it will redirect to Log in page?


dotnet-aspnet-webpages
· 3
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi @EmekaOkoye-3272 ,
According to your description,I think,your problem is that some value are null. I suggest you could debug in the code behind and break point at your codes to check values step by step.
If you still have problems,you could post your codes to us.
Best regards,
Yijing Sun

0 Votes 0 ·

Yes, I know that the value of user ID becomes null when user log out of the site. But what I want is, if the user click the back button after he log out it should redirect to Log In page instead of throwing server error message.

0 Votes 0 ·

Hi @EmekaOkoye-3272 ,
On the click back button event,you need to write Response.Redirect to the login page. I'm guessing that you load the page again when you click the back button. Could you post your codes to us? It will help us to solve your problem.
You could do like this:

 protected void LogoutButton_Click(object sender, EventArgs e)
 {
     FormsAuthentication.SignOut();
     Response.Redirect("~/Login.aspx");
 }

Best regards,
Yijing Sun

0 Votes 0 ·

0 Answers