Mac*_*ver 2 javascript asp.net extjs asmx windows-authentication
如何在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;
}
Run Code Online (Sandbox Code Playgroud)
你可以像这样访问
HttpContext.Current.User.Identity.Name
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
7252 次 |
| 最近记录: |