Click here to Skip to main content
15,881,898 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
Hello,
in my website i have 2 main error pages:
1- 404 error
2- general error page.

in general error page i send an email with the following information to the website admin:
C#
Exception ex = new Exception();
ex = Server.GetLastError();
string errMessage = ex.Message;
string innerMessage = ex.InnerException.Message;
string innerStack = ex.InnerException.StackTrace;
string source =ex.Source;
string stack = ex.StackTrace;

is there a way to get the name of the page that has the error, let's say if the error happens in (login page) i want to redirect to home page.
i know the name of the page will be in
C#
ex.InnerException.StackTrace

i tried the following:
C#
if (ex.InnerException.StackTrace.Contains("login"))
            { Response.Redirect("Home.aspx"); }

but it didn't work
any ideas?

thank you
Samira
Posted
Comments
ramyajaya 16-Apr-15 11:45am    
Try to get the source from the inner exception .

If you can run through the types of exception then you can try with it.


Please provide sample output to support your question
Samira Radwan 16-Apr-15 11:52am    
an example of ex.source is: System.Web
it doesn't give the page's name
ramyajaya 16-Apr-15 12:13pm    
Your exception type is httpexception so in catch process it as httpexception vand fetch the values.

You can use httprequest class to know the current request url information

Use HttpContext.Current.Request .url which will provide you the current request url

1 solution

after long time of trying many ways, i ended up with two ways to display the name of the page that has an error:
1- use Request.UrlReferrer.ToString()
2- use ex.InnerException.StackTrace
i have found that my problem is String.Contains is case sensitive, so using 1 or 2 won't work if i type the name of the page wrong.
if the page called (Login.aspx)
page.Contains("login") won't work!

hope my solution is well explained for anyone has the same issue.

thanks for all who helped me

Samira
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900