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?
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...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With