Created
August 22, 2014 08:39
-
-
Save lski/f93b7ad90186f02dcdc7 to your computer and use it in GitHub Desktop.
To get round the issue of a try/catch/finally being disrupted by transfer and redirection, fill the details of the redirection in this class and run at the end of finally if not null.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// <summary> | |
/// To get round the issue of a try/catch/finally being disrupted by transfer and redirection, fill the details of the redirection in this class and run at the end of finally if not null. | |
/// </summary> | |
public class Redirection | |
{ | |
public enum TransferType | |
{ | |
Redirect, | |
Transfer | |
} | |
public TransferType Type { get; set; } | |
public String Location { get; set; } | |
public HttpContextBase Context { get; set; } | |
public Redirection() | |
: this(new HttpContextWrapper(HttpContext.Current), "", TransferType.Redirect) {} | |
public Redirection(HttpContextBase context, String location, TransferType transferType) { | |
this.Context = context; | |
this.Type = transferType; | |
this.Location = location; | |
} | |
public void Go() | |
{ | |
if (Type == TransferType.Transfer) | |
this.Context.Server.Transfer(this.Location); | |
else | |
this.Context.Response.Redirect(this.Location, false); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment