I need to get user details before hitting the SharePoint Server page.

User hitting sharepoint page(https://spxy) then I redirect to https://spxy/_layouts/TestHandler.ashx via httpmodule.

I need to get IE User logged in Name in the http handler page.


XYZ Domain -- Test User -- John

ABC Domain -- Test User -- Alex

Contoso Domain -- Test User -- Tom

I just logged in windows login as Administrator, If I login in the IE using john then I need to his domain name and user name.

2 Answers 2


You can use JSOM by javascript like two different ways:

Using sp.js _spPageContextInfo.userLoginName

Or you could use REST

function getCurrentUser() {
    var endpointUrl = _spPageContextInfo.webServerRelativeUrl + '/_api/web/currentuser';
    return $.ajax({
            url: endpointUrl,
            method: "GET",
            contentType: "application/json;odata=verbose",
            headers: {   
             "Accept": "application/json;odata=verbose"
        }); }

There are many ways to get logged in user name

SPWeb site = SPControl.GetContextWeb(Context);
SPUser user = site.CurrentUser;
string strUserName = user.LoginName;

or you can use

SPWeb web = SPControl.GetContextWeb(this.Context);
string userName = web.CurrentUser.LoginName;

or you also can use

string userName = this.Context.User.Identity.Name;

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.