How can I get name of file that generates exception.
ex.
addUser.aspx
try
{
SaveUser();
}
catch (Exception ex)
{
response.wrhite(ex.GETPAGE().toString());
}
return addUser.aspx;
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Unfortunately, the
Exceptionclass does not have any information regarding what you are looking for. As Yahia notes here, you can get the class name from the Exception, but as you have found, that does not really help for finding the ASPX path.The best thing to do is to use the
Request.Url.ToString()method from inside your exception handler, as Graham notes. Since your code is running from inside the ASPX.cs related to your page, theRequestobject is available for this.