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
public class ApiAuthorize : AuthorizeAttribute | |
{ | |
protected override void HandleUnauthorizedRequest(AuthorizationContext filterContext) | |
{ | |
filterContext.HttpContext.Items.Add("unauthorized", true); | |
} | |
} |
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
protected void Application_EndRequest() | |
{ | |
var context = new HttpContextWrapper(this.Context); | |
//check if we have an unathorized value in the dictionary | |
if(context.Items.Contains("unauthorized")) | |
{ | |
context.Response.Clear(); | |
context.Response.StatusCode = 401; | |
} |
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
public class ApiAuthorize : AuthorizeAttribute | |
{ | |
protected override void HandleUnauthorizedRequest(AuthorizationContext filterContext) | |
{ | |
var response = filterContext.HttpContext.Response; | |
response.Clear(); | |
response.StatusCode = 401; | |
response.End(); | |
} |
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
public class ApiAuthorize : AuthorizeAttribute | |
{ | |
protected override void HandleUnauthorizedRequest(AuthorizationContext filterContext) | |
{ | |
filterContext.HttpContext.SuppressFormsAuthenticationRedirect = true; | |
} | |
} |
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
namespace WelcomeToMyLair | |
{ | |
public class Greeting | |
{ | |
public Greeting() | |
{ | |
EntryDetection.OnUserVisit += NewUserDetected; | |
} | |
void NewUserDetected(UserInfo info, EventArgs e) |