Our system allows users to auotmatically log into our system with their Windows credentials. Basically in security a user is created with a temp username and they can set a flag for Windows Authentication. The first time they log in we grab their credentials and change the username to their username (MYDOMAIN\JimPike for example). This is all done through the windows programs in our family of products.
In our current web parts, the login web part tries to grab the user name from:
Page.Request.ServerVariables["AUTH_USER"]
We then pass that to our system for login. A client ran into an issue because they are using claims based authentication and instead of the username we expect the above was returning "0#.w|MYDOMAIN\JimPike" and thus login was failing.
I am new to claims authentication. I have watched a couple tutorials and read up on it and I understand that prefix is part of claims that tells us about the identity provider.
o#.w = Windows Identity Provider
o#.f = Forms Identity Provider
0#.t = Trusted Identity Provider
My question is... what is the best way to address this issue in my code? Would this be the proper way of retrieving the username in the "MYDOMAIN\JimPike" form that I want?
SPWeb web = SPControl.GetContextWeb(Context); SPUser currentUser = web.CurrentUser; string userName = currentUser.LoginName;