Skip to main content
SP.ClientContext.get_current() is not a constructor, no need for 'new' keyword
Source Link

To get username or login name using SSOM is very simple

string strUserName = SPContext.Current.Web.CurrentUser.LoginName;

To get username from CSOM

function getCurrentUser() {  
  var context = new SP.ClientContext.get_current();  
   var web = context.get_web();  
  var currentUser = web.get_currentUser();  
  context.load(currentUser);  
  context.executeQueryAsync(onSuccessMethod, onRequestFail);  
}  

You can use this query string to pass username to another URL.Make sure it is encrypted before passing inin url

To get username or login name using SSOM is very simple

string strUserName = SPContext.Current.Web.CurrentUser.LoginName;

To get username from CSOM

function getCurrentUser() {  
   context = new SP.ClientContext.get_current();  
    web = context.get_web();  
  currentUser = web.get_currentUser();  
  context.load(currentUser);  
  context.executeQueryAsync(onSuccessMethod, onRequestFail);  
}  

You can use this query string to pass username to another URL.Make sure it is encrypted before passing in url

To get username or login name using SSOM is very simple

string strUserName = SPContext.Current.Web.CurrentUser.LoginName;

To get username from CSOM

function getCurrentUser() {  
  var context = SP.ClientContext.get_current();
  var web = context.get_web();  
  var currentUser = web.get_currentUser();  
  context.load(currentUser);  
  context.executeQueryAsync(onSuccessMethod, onRequestFail);  
}  

You can use this query string to pass username to another URL.Make sure it is encrypted before passing in url

Source Link
Amit Kotha
  • 2.2k
  • 1
  • 14
  • 18

To get username or login name using SSOM is very simple

string strUserName = SPContext.Current.Web.CurrentUser.LoginName;

To get username from CSOM

function getCurrentUser() {  
   context = new SP.ClientContext.get_current();  
    web = context.get_web();  
  currentUser = web.get_currentUser();  
  context.load(currentUser);  
  context.executeQueryAsync(onSuccessMethod, onRequestFail);  
}  

You can use this query string to pass username to another URL.Make sure it is encrypted before passing in url