// Butchered together from multiple answers if (!Page.IsCallback) Request.Redirect("~/Error.aspx"); else HttpContext.Current.Response.RedirectLocation = System.Web.VirtualPathUtility.ToAbsolute("~/Error.aspx");