Link to home
Start Free TrialLog in
Avatar of rakhy_rakey
rakhy_rakeyFlag for United States of America

asked on

Need to redirect to error page if there is an occur occured in asp.net application

Hi Guys....

I have a requirement where I need to redirect the user to error page if there is an error occurred in application.

Error may be any kind of thing, whether it is Session time out exception Or page not found exception.

For this, I used custom errors setting in web.config file. My custom error file is in Root folder of the application.

I tested the following  scenario in my application:

I set the session time out as 1 minute in web.config file. I ran my application. I waited for 1 minute and came back to application and clicked a button on my application. It is unable to go to my custom page. The problem I found is "custom page is content page for Master page in which a session is already initiated. " So, as already session is expired, it is unable to go to that page.

Then I tested using some public website, Google.com. It is redirected successfully.

So here my question is:

Do I need to give a separate URL  which are not in same project to redirect the user

Can't we have the file added in my project as a separate file instead of having it as a content page ?

I tried it by adding a page as a separate page. that too did not work.

Please solve this problem guys ?

Thanks,
Rakhy.
SOLUTION
Avatar of Dale Burrell
Dale Burrell
Flag of New Zealand image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of rakhy_rakey

ASKER

hi Dale....

Thanks for the reply. I tried it now again by adding a new aspx page for my root folder. It worked. But some how it did not work yesterday.

Any way thank you.

Now I have one more question regarding this.

I just want to write a code in Codebehind of my aspx page to dispolay the message according to the error.

Some blogs on the internet tells that we can use a method, I think we can override application_error in global.asax file to display the message.

What is the difference between these two approaches and which one should be used when ?

Thank you very much for the help...

Rakhy,
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Dale gave me proper guidance to reach the solution. But it is not complete. I also tried to reach my solution by trying in many ways.
rakhy_rakey - my code doesn't do a redirect - it does a transfer and there is a big difference between the 2. Doing a redirect (which is what web.config does) asks the browser to redirect to another page, but by then you've lost all the information about the error. My code does a server transfer, which transfer control from the current page to the error page, retaining the information about the error. Therefore using my code you wouldn't need to store the error details in the database - unless you do actually want a record of them.

Hope that makes sense.