ユーザーはASP.NET Webforms HTTPモジュールで何もしないように設定します

StackOverflow https://stackoverflow.com//questions/25064855

質問

ASP.NET Webアプリケーションでは、以下のカスタムモジュールがあります。このモジュールは私のPCのChromeから機能しますが、Androidからビデオにアクセスしようとすると、USERID(_Context.user)が設定されていないためエラーが発生します。これはすべてアプリケーションにログインした後に発生します。したがって、_context.userを設定する必要があります。

このレベルでは、モジュールが任意のデバイスに対して機能するHTTPリクエストと応答を扱っているため、考えていました。

私は2つの質問があります。

この作業をする方法はありますか?

この問題を引き起こすために、AndroidタブレットとPCによって送信された要求の違いは何ですか?

パブリッククラスビデオセキュリティモジュール IHTTPModuleを実装します IreQuiressessionStateを実装します httpApplication

として_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はCookieを処理できないため、認証CookieはWebアプリケーションに渡されません。_Context.userプロパティが設定されていません。

次のリンクは、詳細な詳細をより詳細に提供します。

href="https://stackoverflow.com/questions/16310552/do-mobile-browsers-send-httponly-cookies-via-the-html5-audio-tag">モバイルブラウザはHTTPONLY Cookieを介して送信しますhtml5 audio-tag? https://code.google.com/p/android/issues/詳細?ID= 17553

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top