Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why do i get i:0#.w|domain\\username and within RunWithElevatedPrivileges domain\apppool?

When i do

Console.WriteLine(SPContext.Current.Web.CurrentUser.LoginName);

i get the following response:

i:0#.w|domain\\username

When i do

SPSecurity.RunWithElevatedPrivileges(delegate() {
    Console.WriteLine(SPContext.Current.Web.CurrentUser.LoginName);
});

i get

domain\appPoolAccount

without i:0#.w|... within the loginname.

Is someone able to explain why this happens?

like image 870
STORM Avatar asked Sep 01 '25 01:09

STORM


1 Answers

The prefix (i:0#.w|) before the username is just an internal code so that SharePoint can identity the type of authentication (w: windows auth, f: formsbased, etc...). The i in the code is to identify that it is a user. FYI if you would try to write out a group, the prefix would be c instead of i.

The fact that you don't have a prefix in elevatedprivileges is that this will always be the admin/pool-account which will always be a windows user - so no need to add the prefix...

like image 69
Verthosa Avatar answered Sep 02 '25 14:09

Verthosa