void Redirect (string url, bool endResponse, int code)
{
if (url == null)
throw new ArgumentNullException ("url");
if (headers_sent)
throw new HttpException ("Headers have already been sent");
if (url.IndexOf ('\n') != -1)
throw new ArgumentException ("Redirect URI cannot contain newline characters.", "url");
is_request_being_redirected = true;
ClearHeaders ();
ClearContent ();
StatusCode = code;
url = ApplyAppPathModifier (url);
bool isFullyQualified;
if (StrUtils.StartsWith (url, "http:", true) ||
StrUtils.StartsWith (url, "https:", true) ||
StrUtils.StartsWith (url, "file:", true) ||
StrUtils.StartsWith (url, "ftp:", true))
isFullyQualified = true;
else
isFullyQualified = false;
if (!isFullyQualified) {
HttpRuntimeSection config = HttpRuntime.Section;
if (config != null && config.UseFullyQualifiedRedirectUrl) {
var ub = new UriBuilder (context.Request.Url);
int qpos = url.IndexOf ('?');
if (qpos == -1) {
ub.Path = url;
ub.Query = null;
} else {
ub.Path = url.Substring (0, qpos);
ub.Query = url.Substring (qpos + 1);
}
ub.Fragment = null;
ub.Password = null;
ub.UserName = null;
url = ub.Uri.ToString ();
}
}
redirect_location = url;
// Text for browsers that can't handle location header
Write ("<html><head><title>Object moved</title></head><body>\r\n");
Write ("<h2>Object moved to <a href=\"" + url + "\">here</a></h2>\r\n");
Write ("</body><html>\r\n");
if (endResponse)
End ();
is_request_being_redirected = false;
}