I have a .Net Core 3.1 MVC app hosted as Azure Web App and enabled Express Authentication. Now in the code, I want the Azure AD Object ID (in Controller/View). In all the examples and samples, I see multiple ways to get information about User details like Name etc. but could not find anything about getting the Object ID. How to get the same?
My Controller is pretty simple, like this:
public IActionResult Index()
{
return View();
}
In View, index.cshtml is also very generic.
In the startup.cs, I have:
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
else
{
app.UseExceptionHandler("/Home/Error");
app.UseHsts();
}
app.UseHttpsRedirection();
app.UseStaticFiles();
app.UseRouting();
app.UseAuthorization();
app.UseEndpoints(endpoints =>
{
endpoints.MapControllerRoute(
name: "default",
pattern: "{controller=Home}/{action=Index}/{id?}");
});
}
Please let me know a way to get the Azure AD Object ID in the Index() method in the Controller.