在设置用户后,从 JavaScript JSON 请求中获取 Web 服务 (asmx) ASP.NET Windows



如何在 ASP.NET Web 服务 (asmx) 中检索经过 Windows 身份验证的用户? 这就是我认为可行的,但"System.Web.UI.Page"不存在。 但是,这在 aspx 页中的代码隐藏中确实有效,因为"System.Web.UI.Page"具有值。 请注意,我从 ExtJS 代理读取请求调用此 Web 方法。 它在 JavaScript 代码中请求一个 JSON 对象。

[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Json, UseHttpGet = false, XmlSerializeString = false)]
public string GetCurrentUserWindowsLogin()
{
    string windowsLogin = Page.User.Identity.Name;
    int hasDomain = windowsLogin.IndexOf(@"");
    if (hasDomain > 0)
    {
        windowsLogin = windowsLogin.Remove(0, hasDomain + 1);
    }
    return windowsLogin;
}

你可以像这样访问

HttpContext.Current.User.Identity.Name 
HttpContext.Current.User.Identity.Name

相关内容

最新更新