Search code examples
c#asp.nethttp-redirectresponse

Response redirect to same page with querystring on page load


I have a page called: Welcome.aspx

In the page load of that page I did: Response.Redirect("Welcome.aspx?First=true")

So when I visit Welcome.aspx the site keeps redirecting and it doesn't stop (logical).

What can I do to stop the redirecting? I just want that the redirect happens just once. So when someone visits Welcome.aspx they must be redirected to Welcome.aspx?First=true just once. And after that the response.redirect must stop.

Thanks!


Solution

  • Only do the redirect if QueryString["First"] is not equal to "true" (though I think your naming and logic don't really match there). Something like:

    void Page_Load( ... )
    {
        if (!Page.IsPostBack)
        {
            if (QueryString["VisitFlag"] == null)
                Response.Redirect("Welcome.aspx?VisitFlag=Done");
        }
    }