I am working to make a solution like the following. An Excel Macro is calling an API written in C#. The C# API takes the user name and does some validation by checking the DB. Currently the UserName is passed like the following
UserName = Environ$("UserName")
RequestMessage & "<UserName>" & UserName & "</UserName>"
However, as you would agree anybody can manipulate the UserName variable. I would like to check the User name in the API, by other means. In the environment we have AD authentication enabled. What should be the possible ways to achieve this. I am not really very highly skilled with API using C#.
I tried this code
string _userName = System.Web.HttpContext.Current.User.Identity.Name;
But that is returning error "HttpContext" does not exist.
I am using .Net Core 8.0.
Any guidance will be helpful.
I have used the following code to achieve what I wanted.
This code above is giving me the user name, who is calling the API.