Answered by:
problem getting network user id - svc-webapps shows up instead

Question
-
User1395831461 posted
I have an aspx page that uses some code behind to populate a textbox with the network user id...
System.Security.Principal.WindowsIdentity a = System.Security.Principal.WindowsIdentity.GetCurrent();
BoxRecordCreatedBy.Text = a.Name.Split(new char[] { '\\' })[1];
...and in my web config have windows authentication turned on...
<authentication mode="Windows" />
...but was getting 404 error until I added this to my web.config...
<appSettings> <add key="owin:AutomaticAppStartup" value="false"/> </appSettings>
...so now the page loads and when I run the page in debug my userid populates the textbox as expected but after I publish the page and access it it populates the textbox with a service account...
svc-webapps
Windows authentication is enabled on the IIS server as well.
Could someone kindly show me what I'm doing wrong and how to correct it?
Thanks as tonne, Roscoe
Thursday, November 19, 2015 4:09 PM
Answers
-
User753101303 posted
Hi,
Use System.Web.HttpContext.Current.User.Identity.Name to get the authenticated user. Currently you get the account under which the code runs (which is yours when running VS making hard to see it won't be the information you want when running on a real web server).
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Thursday, November 19, 2015 4:34 PM -
User-2010311731 posted
Try using Context.User.Identity.Name instead.
Matt
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Thursday, November 19, 2015 5:37 PM
All replies
-
User753101303 posted
Hi,
Use System.Web.HttpContext.Current.User.Identity.Name to get the authenticated user. Currently you get the account under which the code runs (which is yours when running VS making hard to see it won't be the information you want when running on a real web server).
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Thursday, November 19, 2015 4:34 PM -
User-2010311731 posted
Try using Context.User.Identity.Name instead.
Matt
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Thursday, November 19, 2015 5:37 PM