I am trying to store the url in a Session to be picked up later when I redirect the Response to tidy up my URL. This is in the Global.asax file. I am taking the original response and storing the url in a session
protected void Application_Error(object sender, EventArgs e)
{
Exception exception = Server.GetLastError();
HttpException httpException = exception as HttpException;
// get the url
var url = Request.RawUrl;
// store in session
Session["requestUrl"] = url;
if (exception is HttpException && ((HttpException)exception).GetHttpCode() == 404) {
Response.Redirect("/CMS/CMS");
}
}
If I look at the Session contents it is in there
I then try to extract this in my CMS/CMS Action but the variable url is null??:
public ActionResult CMS(String aspxerrorpath)
{
var url = Session["requestUrl"]; // this is null??
Response.StatusCode = 404;
Response.TrySkipIisCustomErrors = true;
return View();
}
Any Ideas?