ASP.NET Generic Handler(.ashx)によって、現在ログインしているユーザーのユーザー名を取得しようとしています。ただし、ユーザーが現在ログインしている場合でも、ユーザー名は常に何もありません。
これが私のジェネリックハンドラークラスです:
Imports System.Web.SessionState
Public Class FileUploadHandler
Implements System.Web.IHttpHandler
Implements IRequiresSessionState
Sub ProcessRequest(ByVal context As HttpContext) Implements IHttpHandler.ProcessRequest
'username is always null, i'm not sure why there's nothing eventhough the user is logged in
Dim username = context.Current.User.Identity.Name
If String.IsNullOrEmpty(username) Then
context.Response.StatusCode = 0
Else
context.Response.StatusCode = 1
End If
End Sub
ReadOnly Property IsReusable() As Boolean Implements IHttpHandler.IsReusable
Get
Return False
End Get
End Property
End Class
しかし、ログインしたユーザーのユーザー名は、次のような任意のページから取得できます。
Dim username = Context.Current.User.Identity.Name
ここでの問題は何だと思いますか?C#とVB.NETの両方で問題ありません。ありがとう。