사용자는 ASP.NET WebForms HTTP 모듈에서 아무 것도 설정하지 않습니다
-
23-12-2019 - |
문제
ASP.NET 웹 응용 프로그램에서 아래의 사용자 정의 모듈이 있습니다.모듈은 내 PC에서 Chrome에서 작동하지만 Android에서 비디오에 액세스하려고 할 때 사용자 ID (_context.user)가 설정되지 않기 때문에 오류가 발생합니다.이 모든 것은 응용 프로그램에 로그인 한 후에 발생합니다.따라서 _context.user를 설정해야합니다.
이 레벨에서 모듈이 모든 장치에서 작동하는 HTTP 요청 및 응답을 처리하기 때문에 생각했을 것입니다.
두 가지 질문이 있습니다.
이 작업을 수행하는 방법이 있습니까?
안드로이드 태블릿 및 PC가 보낸 요청의 차이는이 문제를 일으키는 것입니까?
공용 클래스 VideosecurityModule. ihttpmodule을 구현합니다 irequiressessionstate를 구현합니다 개인 withEvents _context
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 Log(value As String, ParamArray args As Object())
Dim message As String = String.Format(value, args)
Dim messagePrefix As String = String.Format("{0},{1},{2},{3}", UserAgent, Url, SessionId, message)
LogManager.WriteMessage(messagePrefix, "")
End Sub
Private ReadOnly Property UserAgent() As String
Get
Try
Return _context.Request.UserAgent
Catch ex As Exception
Return "No User Agent"
End Try
End Get
End Property
Private ReadOnly Property Url() As String
Get
Try
Return _context.Request.Url.PathAndQuery
Catch ex As Exception
Return "No URL"
End Try
End Get
End Property
Private ReadOnly Property SessionId() As String
Get
Try
Return __context.Session.SessionID
Catch ex As Exception
Return "No URL"
End Try
End Get
End Property
Public ReadOnly Property IsReusable() As Boolean
' IsReusable must be set to false since class has a member!
Get
Return True
End Get
End Property
Public Sub OnAuthorizeRequest(ByVal source As Object, ByVal e As EventArgs) Handles _context.AuthorizeRequest
If IsVideoUrl() Then
Dim userId As Integer = GetLoggedInUsersId()
Log("UserRequiresAuthorization({0}): {1}", userId, UserRequiresAuthorization(userId))
Log("UserIsAssignedToCourseContainingVideo({0}): {1}", userId, UserIsAssignedToCourseContainingVideo(userId))
' if user is not assigned to a course that utilizes the video or the user is not in role super user or system admin
If (UserRequiresAuthorization(userId) AndAlso Not UserIsAssignedToCourseContainingVideo(userId)) Then
SendAuthenticationRequiredResponse()
End If
End If
End Sub
Private Function GetLoggedInUsersId() As Integer
Dim userId As Integer = 0
If (Not _context.User Is Nothing) Then
userId = myUserManager.GetUserIdByUserName(_context.User.Identity.Name)
End If
Log("userId:{0}", userId)
Return userId
End Function
Private Sub SendAuthenticationRequiredResponse()
Const networkAuthenticationRequiredStatusCode As Integer = 511
_context.Response.StatusCode = networkAuthenticationRequiredStatusCode
_context.Response.ClearContent()
_context.Response.Write("UnAuthorized User")
Log("UnAuthorized User: {0}", "")
_context.Response.End()
End Sub
Private Function IsVideoUrl() As Boolean
Dim fileLocation As String = System.Configuration.ConfigurationManager.AppSettings("VideoLocation")
Log("url:{0}", _context.Request.Url)
Log("IsVideoUrl:{0}", _context.Request.FilePath.ToLower().Contains(fileLocation.ToLower()))
Return _context.Request.FilePath.ToLower().Contains(fileLocation.ToLower())
End Function
Private Function UserDoesNotRequireAuthorization(userId As Integer) As Boolean
Return myUserManager.IsSysAdmin(userId) OrElse myUserManager.IsSuperUser(userId)
End Function
Private Function UserRequiresAuthorization(userId As Integer) As Boolean
Dim result As Boolean = Not UserDoesNotRequireAuthorization(userId)
Return result
End Function
''' <summary>
''' Returns true if the in-putted user (logged in user) has been allocated to a course that utilize video specified in this request
''' </summary>
Private Function UserIsAssignedToCourseContainingVideo(userId As Integer) As Boolean
' ... code removed for clarity
End Function
.
엔드 클래스
해결책
숫자 버전의 Android의 알려진 문제점입니다.제한된 연구는 비디오 요청이 StageFright라는 Android에서 별도의 구성 요소로 전달되었음을 암시합니다.stagefright는 쿠키를 처리 할 수 없으므로 인증 쿠키가 _context.user 속성이 설정되지 않은 웹 응용 프로그램에 전달되지 않습니다.
다음 링크는 깊이 세부 정보를 더 많이 제공합니다.
모바일 브라우저가 httponly 쿠키를 통해HTML5 오디오 태그? https://code.google.com/p/android/issues/세부 사항? ID= 17553