Help Needed. I have an http module that worked using VS2010 Development studio but now it does not.
After deploying the module to IIS 7 I have found that _context.User is set to null when processing Images, Videos, CSS and Images. This is causing issues with my below code.
The module is to determine if a user has access to a specific video but again when the request is processed the I can not determine who the currently logged on user is.
public Class VideoSecurityModule
Implements IHttpModule
Private WithEvents _context As HttpApplication
Public Sub Dispose() Implements IHttpModule.Dispose
End Sub
Dim myUserManager As UserManager
Public Sub Init(ByVal context As HttpApplication) Implements IHttpModule.Init
_context = context
myUserManager = New UserManager
End Sub
Public Sub OnAuthorizeRequest(ByVal source As Object, ByVal e As EventArgs) Handles _context.PostAuthenticateRequest
Const networkAuthenticationRequiredStatusCode As Integer = 511
Try
If IsVideoUrl() Then
Dim userId As Integer = myUserManager.GetUserIdByUserName(_context.User.Identity.Name)
If (UserRequiresAuthorization(userId)) Then
If Not UserIsAssignedToCourseContainingVideo(userId) Then
LogAccessDeniedMessage()
_context.Response.StatusCode = networkAuthenticationRequiredStatusCode
_context.Response.ClearContent()
_context.Response.Write("UnAuthorized User")
_context.Response.End()
End If
End If
End If
Catch ex As Exception
LogManager.WriteException(ex, "")
End Try
End Sub
End Class
I have been working on this for days and am at a loss to what I can do.
I see you are using FormsAuthentication & Anonymous Authentication, which is similar to thread: (However for your files, I know, you may definitely have the extensions but just wanted to check if this is due to skipping of few modules causing issue).
Could you try putting this flag: runAllManagedModulesForAllRequests="true"?
Yes. You're welcome. Glad to help you. However, running all the modules for each request may not be a good choice. I'll try to find out a better way of doing this.
You may copy the FormsAuthentication tag above from your machine to avoid any namespace changes across the framework releases etc.
You can find the FormsAuthentication tag from your base config file in this probable location: C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Config\web.config - (You may have different version nunmber in this path).
Reference: http://stackoverflow.com/a/20164054
Member
47 Points
81 Posts
_context.User is Null in HTTPModule
Jul 22, 2014 08:02 AM|someguyonacomputer|LINK
Help Needed. I have an http module that worked using VS2010 Development studio but now it does not.
After deploying the module to IIS 7 I have found that _context.User is set to null when processing Images, Videos, CSS and Images. This is causing issues with my below code.
The module is to determine if a user has access to a specific video but again when the request is processed the I can not determine who the currently logged on user is.
I have been working on this for days and am at a loss to what I can do.
Star
9052 Points
2255 Posts
Re: _context.User is Null in HTTPModule
Jul 22, 2014 08:10 AM|Siva Krishna Macha|LINK
Could you also post the configuration snippet you have made for this specific module inside web.config?
Thanks & Regards,
Siva
Member
47 Points
81 Posts
Re: _context.User is Null in HTTPModule
Jul 22, 2014 08:25 AM|someguyonacomputer|LINK
The above is the http module sections in the web.config file for the application deployed to IIS
Star
9052 Points
2255 Posts
Re: _context.User is Null in HTTPModule
Jul 22, 2014 08:39 AM|Siva Krishna Macha|LINK
It looks like the problem is with the identity. You may try some of the following options:
1. By switching the appPool from Integrated mode to Classic mode.
2. By enabling the Anonymous access (and/or) Windows Authentication.
http://stackoverflow.com/questions/1663535/httpcontext-current-user-is-null-even-though-windows-authentication-is-on
Thanks & Regards,
Siva
Member
47 Points
81 Posts
Re: _context.User is Null in HTTPModule
Jul 22, 2014 08:51 AM|someguyonacomputer|LINK
1. I can not switch to classic as it is an existing application. I Did try it for debugging purposes and nothing.
2. Anonymous and Forms authentication is enabled and required.
Star
9052 Points
2255 Posts
Re: _context.User is Null in HTTPModule
Jul 22, 2014 09:21 AM|Siva Krishna Macha|LINK
I see you are using FormsAuthentication & Anonymous Authentication, which is similar to thread: (However for your files, I know, you may definitely have the extensions but just wanted to check if this is due to skipping of few modules causing issue).
Could you try putting this flag: runAllManagedModulesForAllRequests="true"?
Reference: http://forums.asp.net/t/1689878.aspx?HttpContext+Current+User+always+null+on+IIS+
Thanks & Regards,
Siva
Member
47 Points
81 Posts
Re: _context.User is Null in HTTPModule
Jul 22, 2014 09:35 AM|someguyonacomputer|LINK
Thank you very much. _context.User is now set.
so setting the runAllManagedModulesForAllRequests="true" must make other module that are responsible for setting the context.User property to run.
Star
9052 Points
2255 Posts
Re: _context.User is Null in HTTPModule
Jul 22, 2014 09:58 AM|Siva Krishna Macha|LINK
Yes. You're welcome. Glad to help you. However, running all the modules for each request may not be a good choice. I'll try to find out a better way of doing this.
Thanks & Regards,
Siva
Star
9052 Points
2255 Posts
Re: _context.User is Null in HTTPModule
Jul 22, 2014 10:09 AM|Siva Krishna Macha|LINK
Just so if this may help you - to run ONLY formsAuthenticationModule always.
http://stackoverflow.com/a/22461736
Snippet as below: (Notice precondition value is set to empty instead of Managed).
You may copy the FormsAuthentication tag above from your machine to avoid any namespace changes across the framework releases etc.
You can find the FormsAuthentication tag from your base config file in this probable location: C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Config\web.config - (You may have different version nunmber in this path).
Reference: http://stackoverflow.com/a/20164054
Thanks & Regards,
Siva