locked
Get Username RRS feed

  • Question

  • User-284642143 posted

    I have a web application with a Sql backend. It also has ASP .Net forms authentication enabled with users and groups setup. For certain areas i would require the user to have a username and password to view content. The problem i have is when a user hits a button it runs this code:

    Return Environment.UserName

     

    This shows me the logged on username as expected, but when i deploy the application i have Network Service, I unticked allow anonymous access in IIS for this site and it still returns as Network Service. How could i retrieve the logged on users name and not Network Service?

    Thanks

    Friday, October 16, 2009 10:50 AM

Answers

  • User-2008565010 posted

    try setting Impersonation.

    Check this: http://www.bluevisionsoftware.com/WebSite/TipsAndTricksDetails.aspx?Name=AspNetAccount


    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, October 16, 2009 1:03 PM

All replies

  • User-2008565010 posted

    1: make sure you have Forms authentication set in your applicaiton's web.config file.

    2: get username using HttpContext.Current.User.Identity.Name



    Friday, October 16, 2009 12:11 PM
  • User-284642143 posted

    1. I have it set to

      <authentication mode="Forms" />


    2. I should have stated i require the windows logged on name and not the username they log on with to the site. Ths code shows the name as expected but when deployed it doesn't

    Return Environment.UserName

    Still doesnt work as it does in my dev environment. 

    Friday, October 16, 2009 12:38 PM
  • User-2008565010 posted

    what username is displayed on your dev ? ASPNET?

    What is your dev machince (XP)???

    Friday, October 16, 2009 12:51 PM
  • User-284642143 posted

    This shows me the logged on username as expected, but when i deploy the application i have Network Service

    i.e. If i am logged on as Tony then username is back as Tony (on the dev machine).

    Dev machine is Vista Business 

    Friday, October 16, 2009 12:57 PM
  • User-2008565010 posted

    try setting Impersonation.

    Check this: http://www.bluevisionsoftware.com/WebSite/TipsAndTricksDetails.aspx?Name=AspNetAccount


    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, October 16, 2009 1:03 PM
  • User-284642143 posted

    Thanks, that worked. On another similar point when i tried to get the computer name it came back with the server name - any other way to retrieve the PC name the user is logged on to?

    Friday, October 16, 2009 4:10 PM