ASP.NET Find out which Response.Redirect is being redirected to?

I have a huge site with a huge backend. Somewhere, one way or another, the Response.Redirect response appears when trying to open the site (debug environment).

Is there a way to find out which Response.Redirect is causing the redirect?

A specific way would be to set a debug breakpoint on every Response.Redirect throughout the website. But this is a lot of effort.

Another idea I had was to stop at "ThreadAbortException" (which is called by Response.Redirect) with "Debug-> Exceptions ..". But it doesn't work. It seems like a frame or something else is not done to get the pause.

The last attempt was to look at the call stack. But the stack never gets to the last Response.Redirect because it's a new frame call.

+3


source to share


4 answers


Well, I have an idea that solved my problem, but required a massive code replacement (which is not a Find and Replace problem).

I created a static class:

public static class OwnResponse
{
    public static void Redirect(string Url, bool EndResponse = true)
    {
        HttpContext.Current.Response.Redirect(Url, EndResponse); // set the breakpoint here
    }
}

      



Then I replaced every Response.Redirect in the code with OwnResponse.Redirect. Now I was able to set a breakpoint on the first line in the class. I called the site and the breakpoint hit. Then I just looked at the call stack and knew where the redirection was going.

There is another possible solution that requires a little more work. You must get "Stepping into .NET code" to run. Then you can easily set a breakpoint on the first line of the .NET method.

+1


source


You can use below code on landing page: -

string yourPreviousUrl = Request.UrlReferrer.ToString();

if(!string.IsNullOrEmpty(yourPreviousUrl))
{
    //Referrer was found!
}
else
{
    //Unable to detect a Referrer
}

      

As mentioned on the official website: -



HttpRequest.UrlReferrer Property

Gets information about the URL of the previous client request that is associated with the current URL.

0


source


You can try to implement tracing and save the results to a file. Trace information can help you determine the redirection.

Here is a link with another background to ASP.NET tracing:

http://www.codeproject.com/Articles/82290/Step-by-Step-Guide-to-Trace-the-ASP-NET-Applicatio

0


source


Use fiddler or other HTTP traffic capture tool and capture network traffic. You should see the request that was initiated and take it from there.

0


source







All Articles