動画リクエストが /website/uploads/Video/M2U00001_2.mp4 などの HTTP モジュール (以下のコード) によって処理される場合、_context.User
は null です。
Visual Studio 開発サーバーを使用してローカル マシンの VS2010 でこれを実行すると、_context.User
設定されます。IIS 7 (.net 4.0) にデプロイした後、_context.User は Null です。
「_context.User」は、http モジュールが aspx ページを処理する場合は Null ではありませんが、javascript、画像、ビデオ、または CSS を処理する場合は Null です。
なぜ_context.User
nullであり、_context.Userがnullでないことを保証する可能な解決策を誰でも説明できますか?
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
If _context.User Is Nothing Then
LogManager.WriteMessage("_context.User is nothing:", "")
End If
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