This is in the HttpModule.
public void Init(HttpApplication application)
{
_httpApplication = application; _
httpApplication.AuthenticateRequest += OnAuthenticateRequest;
}
public void OnAuthenticateRequest(object sender, System.EventArgs e)
{
_customclass.Process(_httpApplication.Context);
}
In the _customClass process method
private HttpContext _context;
public void Process(HttpContext context)
{
_context = context;
var authenticationTicket = GetCurrentAuthenticationTicket();
if (authenticationTicket == null)
{
var userEmail = GetEmail();
CreatePrincipalAndSetAsCurrentUser(userEmail);
authenticationCookie = CreateAuthTicket( CustomIdentityObject);
_context.Response.AppendCookie(authenticationCookie);
}
else if (authenticationTicket.Expired)
{
RedirectAndEndResponse("~/Logout.aspx");
}
else
{
CreatePrincipalAndSetAsCurrentUser(authenticationTicket);
}
}
CreatePrincipalAndSetAsCurrentUser
private ICustomPrincipal CustomPrincipal
{
get { return _context.User as ICustomPrincipal ; }
set { _context.User = value; }
}
When we try to access HttpContext.Current.User
as ICustomPrincipal
, the application is throwing below error
Object reference not set to an instance of an object.
As mentioned above, this works fine in Local and also in IIS but, the issue happens only in Azure App Service. Tried to create custom principal in PostAuthenticateRequest
but the application is behaving weird.
New contributor
Sam P is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
10