How to get user profile for your machine when application hosted on iis using asp.net mvc ?

Ahmed Salah Abed Elaziz 390 Reputation points
2023-12-18T23:30:49.85+00:00

I work on asp.net MVC application . suppose my user name of my pc is Michel

so i need to rerun this name Michel when application hosted on iis

so i can insert this name with every transaction done and which user insert transactions

i face issue on that it always return name of application on iis hosted app

so how to solve that please

Windows development | Internet Information Services
Developer technologies | ASP.NET | Other
{count} votes

3 answers

Sort by: Most helpful
  1. Bruce (SqlWork.com) 78,311 Reputation points Volunteer Moderator
    2023-12-18T23:47:16.1533333+00:00

    you don't show the code you use to get the name, or what authentication your site is using. you should also specify if asp.net core or old framework.


  2. AgaveJoe 30,126 Reputation points
    2023-12-19T10:57:52.9466667+00:00

    This is similar to another one of your recent questions that asks how to get the user's computer name. Getting the user's system login username only works if all the computers are on an Intranet (internal network) and the network uses Windows Authentication. Then you can enable Windows Authentication in IIS to get the user's username.

    Authenticating Users with Windows Authentication (C#)

    If you are not building an Internet application then use a standard Authentication/Authorization framework like Identity to cache the user name in an authentication cookie. Use the "Individual Account" when creating a new web application in Visual Studio for example code.

    Introduction to ASP.NET Identity

    You tagged your post as ASP.NET. If you are building an ASP.NET Core application, then read the docs for Core.

    0 comments No comments

  3. Lex Li 6,037 Reputation points
    2023-12-20T02:58:54.9733333+00:00

    For ASP.NET 4.x, you just need to make sure the right API is being used to learn the logon user. I wrote about that in this post a while ago.

    No big change even if you are using ASP.NET Core.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.