Reputation: 63
I am working on a website right now and when people have 404 it redirects them using this code.
<customErrors mode="On">
<error statusCode="404" redirect="/errors/404.aspx?path="/>
</customErrors>
How can I make it so when it is redirecting them it also puts the path its redirecting them from?
So if they were on mysite.com/shfsd.aspx it would redirect as /errors/404.aspx?path=shfsd.aspx
Upvotes: 1
Views: 39
Reputation: 5596
I am not aware of any way to capture the URL referrer in a query string like this.
However, you could easily add code to your 404.aspx.cs
code-behind and do what you like with it:
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
if (Request.Url != null)
{
var url = Request.Url.AbsoluteUri;
//Do something like write to log file etc.
//log.Write(url);
}
else
{
//Handle error from client who directly entered URL..
}
}
}
Upvotes: 1