Is it possible to use the Response.AddHeader particularly Im trying to use the “Refresh” of it. I need it to pause before it redirects but the place where the code is being ran is in a ASCX in the codebehind. It does nothing when I have the following in my Codebehind:
HttpContext.Current.Response.AddHeader("Refresh", "6;URL=Default.aspx");
Any way I can redirect a user in the codebehind on a ascx page?
I don’t know why that isn’t working for you – it seems to be the right syntax to add the redirect to your HTTP header, and it works for me on several browsers. To debug this, you can run Fiddler or a similar tool to see the full HTTP response, and see if it’s not making it to the header.
You may want to try reformatting slightly – the examples I’ve seen have a space between the semi-colon and the
url, andurlkeyword in lower-case. I doubt this is the problem, but worth a try, if it’s failing on specific browsers:An alternative approach, maybe easier to debug, is to use a meta tag instead of HTTP header, so it actually shows up in the markup. Something like:
This will add a
<meta>tag to your<head>section, which should have the desired effect.