I am trying to get the Request.RawURL string on an ASP error in Global.aspx.
Here is my code snippet as written in MS JavaScript:
function Application_Error(sender:Object, e:EventArgs)
{
var sIP:String=Request.ServerVariables("Remote_Addr")
var sError:String;
var err:HttpException=Server.GetLastError();
sError="<h1>"+err.InnerException.Message+"</h1>";
var sMsg=err.GetHtmlErrorMessage().ToString();
sError+="<p>"+sMsg+"</p>";
I did not write this. I am not familiar with this function.
I hope this is enough information.
Thanks
I found another code snippet that is written in C#:
protected void Application_Error(object sender, EventArgs e)
{
// Code that runs when an unhandled error occurs
HttpException lastErrorWrapper = Server.GetLastError() as HttpException;
Exception lastError = lastErrorWrapper;
if (lastErrorWrapper.InnerException != null)
lastError = lastErrorWrapper.InnerException;
string lastErrorTypeName = lastError.GetType().ToString();
string lastErrorMessage = lastError.Message;
string lastErrorStackTrace = lastError.StackTrace;
string YSODmarkup = lastErrorWrapper.GetHtmlErrorMessage();
const string ToAddress = "xxxxxx";
const string FromAddress = "xxxxxx";
const string sWebsite="xxxxx (2020 Website)";
const string Subject = "An Error Has Occured at "+sWebsite;
string sCIP=Request.ServerVariables["Remote_Addr"];
string sAgent = Request.ServerVariables["HTTP_User_Agent"];
//Create MailMessage object//
System.Net.Mail.MailMessage mm = new System.Net.Mail.MailMessage(FromAddress, ToAddress);
mm.Subject = Subject;
mm.IsBodyHtml = true;
mm.Priority = System.Net.Mail.MailPriority.High;
mm.Body = string.Format(@"
<html><head></head><body style=""font-family:verdana;"">
<h1 style=""font-family:Verdana; font-size:10px; font-weight: bold;"">An Error Has Occurred!</h1>
<table cellpadding=""5"" cellspacing=""0"" border=""1"">
<tr>
<td style=""text-align: right;font-weight: bold"">URL:</td>
<td>{0}</td>
</tr>
<tr>
<td style=""text-align: right;font-weight: bold"">IP Address:</td>
<td>{1}</td>
</tr>
<tr>
<td style=""text-align: right;font-weight: bold"">User Agent:</td>
<td>{2}</td>
</tr>
<tr>
<td style=""text-align: right;font-weight: bold"">Exception Type:</td>
<td>{3}</td>
</tr>
<tr>
<td style=""text-align: right;font-weight: bold"">Message:</td>
<td>{4}</td>
</tr>
</table>
</body>
</html>",
Request.RawUrl,
sCIP,
sAgent,
lastErrorTypeName,
lastErrorMessage,
YSODmarkup,
lastErrorStackTrace.Replace(Environment.NewLine, "<br />"));
//Attach the Yellow Screen of Death for this error
//string YSODmarkup = lastErrorWrapper.GetHtmlErrorMessage();
This has the Request.RawUrl string.