How can I retrieve the Windows authenticated user in an ASP.NET web service (asmx)? This is what I thought would work, but “System.Web.UI.Page” doesn’t exist. This does however work in the code behind in an aspx page because “System.Web.UI.Page” has a value. Note, I’m calling this web method from an ExtJS proxy read request. It’s requesting a JSON object in the JavaScript code.
[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;
}
you can access like this