I am using a custom authorize attribute in my MVC 4 web site which acts as a global action filter. Code is pretty pretty simple like below:
public class CustomAuthorizeAttribute : AuthorizeAttribute
{
public override void OnAuthorization(AuthorizationContext filterContext)
{
var user = Membership.GetUser(filterContext.HttpContext.User.Identity.Name, true);
if (!filterContext.HttpContext.User.Identity.IsAuthenticated || user == null || !user.IsApproved || user.IsLockedOut|| !System.Web.Security.Roles.GetRolesForUser().Any() )
{
HandleUnauthorizedRequest(filterContext);
}
base.OnAuthorization(filterContext);
}
}
This works absolutely fine but in one of the action methods in my application which is called by $.getJSON request filterContext.HttpContext.User property is getting null. I am sending a concatenated string in the data parameter with my getJson request, if the length of this string is large then only I'm facing this issue otherwise I never receive null User. Any help will be really appreciated.