Skip to content

Instantly share code, notes, and snippets.

@sitefinitysteve
Created November 11, 2014 13:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sitefinitysteve/9d22b8ea8e0856e5f465 to your computer and use it in GitHub Desktop.
Save sitefinitysteve/9d22b8ea8e0856e5f465 to your computer and use it in GitHub Desktop.
Application_Error to handle document passthrough
protected void Application_Error()
{
//Sitefinity Logger should send to raygun now
var exception = Server.GetLastError();
//Send document requests over to login
if(exception.Message.Contains("You are not authorized to 'View document'") || exception.Message.Contains("You are not authorized to 'View image'")){
if (!ClaimsManager.GetCurrentIdentity().IsAuthenticated)
{
//If user is anonymous, send them to the login
var defaultUrl = Config.Get<ProjectConfig>().DefaultSite.FrontEndLoginPageUrl;
//Clear errors
HttpContext.Current.ClearError();
//Send the user to your loginpage
Response.Redirect("{0}?ReturnUrl=/Download.aspx%3ffile={1}".Arrange(defaultUrl, HttpContext.Current.Request.Url.AbsoluteUri.Replace("?", "%3f")));
}
}
//Other error processing like Raygun.io or whatever...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment