I need to do a 301 redirect for certain urls. Following is the skeleton of the code
public override RouteData GetRouteData(HttpContextBase httpContext)
{
.
.
.
if (newUrl.Length > 0)
{
response.Status = "301 Moved Permanently";
response.RedirectLocation = newUrl;
response.End();
}
}
This works well. It redirects correct for certain Urls. However, I want to have a way to detect that a 301 redirect happened in the next request. So I wish to use a flag as part of Session variables. Something like this:
httpContext.Session["RedirectHappened"] = true;
But Session object is null. How do I access session? Or is there any other way to detect if the current 200 OK request was a result of a previous 301 redirect.
Thanks.