MyMasterPage.master
<head runat="server">
<script type="text/javascript">
$(document).ready(function() {
var userName = '<%# System.Web.HttpContext.Current.Request.ServerVariables["AUTH_USER"].ToString() %>';
alert(userName);
$.ajax({ type: "POST",
url: "DemoWebService.asmx/GetFulName",
contentType: "application/json; charset=utf-8",
dataType: "xml",
dataType: "json",
data: "{'networkId':'" + userName + "'}",
processData: false,
error: function(XMLHttpRequest, textStatus, errorThrown) { ajaxError(XMLHttpRequest, textStatus, errorThrown); },
success: function(xml) { ajaxFinish(xml); }
});
});
</script>
</head>
Even though the userName variable is blank, I get the logged in user from my WebMethod:
[WebMethod]
public string GetFulName(string networkId)
{
//return networkId + " Full Name";
return networkId + " From Server: " + System.Web.HttpContext.Current.Request.ServerVariables["AUTH_USER"].ToString();
}
Since I am checking on the master page, what is the best practice to store the authentication result so that I do not have to check on everypage. Prior to using jquery I was storing in Session.
Thanks
web.config
<authentication mode="Windows"/>
<webServices>
<protocols>
<add name="HttpPost"/>
<add name="HttpGet"/>
</protocols>
</webServices>