我试图通过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