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

Jignesh KumarRank #91 · 22.9K reputationPosted Dec 18, 2023, 11:46 PM EST
Hello Ahemd,
you can access user profile information through the
HttpContextobject.using System.Web.Mvc; public class HomeController : Controller { public ActionResult Index() { // Access user profile information var user = HttpContext.User; // Check if the user is authenticated if (user.Identity.IsAuthenticated) { // Access user properties string username = user.Identity.Name; string authenticationType = user.Identity.AuthenticationType; // You can also access additional information if available if (user.Identity is System.Security.Principal.FormsIdentity formsIdentity) { var ticket = formsIdentity.Ticket; // Access ticket properties such as UserData string userData = ticket.UserData; } // Add extra logic here as per your requirement // ... return View(); } else { return RedirectToAction("Login", "Account"); } } }Jayraj ChhayaRank #304 · 8.2K reputationPosted Dec 19, 2023, 1:02 AM EST
Hello,
To retrieve the user profile for the machine when your ASP.NET MVC application is hosted on IIS, you can use the
Environment.UserNameproperty. This property returns the username of the currently logged-in user on the server where the application is running.However, since you want to display the username of the PC where the application is accessed, you need to use a different approach. One way to achieve this is by using JavaScript on the client-side to retrieve the PC username and send it to the server.
Here's an example of how you can accomplish this:
var pcUsername = ''; // Send the pcUsername to the server using AJAX or include it in your form submissionpublic ActionResult YourAction(string pcUsername) { // Insert the pcUsername with every transaction or perform any other logic return View(); }By using this approach, you will be able to capture the PC username and use it in your application, regardless of whether it is hosted on IIS or accessed from a different machine.