我試圖通過ASP.NET通用處理程序(.ashx)獲取currely登錄用戶的用戶名。但是,用戶名是始終沒有即使用戶當前已登錄獲取用戶名和ASP.NET通用Hanlder
這裏是我的通用處理程序類:
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。謝謝。
看起來像一個重複:http://stackoverflow.com/questions/9524466/httpcontext-current-user-identity-name-not-working-in-ashx-hander – Vedran 2012-07-19 09:48:24