1

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>

1 Answer 1

1

You could store the result in a cookie, and then check that cookie on subsequent pages to get the logged in user's name. You would want to make sure and delete the cookie if the user logged out or their authenticated session expired.

There is a plugin available for jQuery to support reading/writing/deleting cookies.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.