stayclaxxy
stayclaxxy
CC#
Created by stayclaxxy on 7/18/2024 in #help
MVC w/ Razor View - Form POST
Hi All, I am trying to wrap my head around MVC in Razor pages, as I inherited some legacy stuff at work. I am trying to figure out why when I click my "submit" button on my Razor page, a blank page renders, and my breakpoint in my controller method for the post is never hit. What am I doing wrong? Relevant code: https://i.imgur.com/aUtf6YA.png
13 replies
CC#
Created by stayclaxxy on 10/6/2023 in #help
❔ Calling an Azure AD protected Web API endpoint from an Azure AD protected Web App [.NET 7]
I am having trouble getting the correct flow/configuration to call my Web API Endpoint that is protected with Azure AD. This is how the Authentication is configured on the web API currently:
builder.Services.AddMicrosoftIdentityWebApiAuthentication(builder.Configuration, "AzureAd");
builder.Services.AddMicrosoftIdentityWebApiAuthentication(builder.Configuration, "AzureAd");
The Configuration just has the details like clientId, TenantId, Domain, Audience and secret, etc. This is how I am setting up authentication on the web app: (the only scope is an expose API from the API App registration named "WeatherForecast")
string[] initialScopes = new[] { "api://33..38/WeatherForecast" };

// Add services to the container.
builder.Services.AddAuthentication(OpenIdConnectDefaults.AuthenticationScheme)
.AddMicrosoftIdentityWebApp(builder.Configuration)
.EnableTokenAcquisitionToCallDownstreamApi(initialScopes)
.AddInMemoryTokenCaches();
string[] initialScopes = new[] { "api://33..38/WeatherForecast" };

// Add services to the container.
builder.Services.AddAuthentication(OpenIdConnectDefaults.AuthenticationScheme)
.AddMicrosoftIdentityWebApp(builder.Configuration)
.EnableTokenAcquisitionToCallDownstreamApi(initialScopes)
.AddInMemoryTokenCaches();
My question is, how do I get the access token to add to the authorization header to call my web api endpoint? The endpoints are role-based based on the user's roles, so is On-Behalf-Of flow the correct flow to use here? If so, I have looked at Microsoft's examples, and I am still very confused on how to achieve what I want to do. TIA!
9 replies
CC#
Created by stayclaxxy on 1/26/2023 in #help
❔ EFCore in .net 6 Web API - using same context/model for multiple environments simultaniously.
I am trying to write a Web API, one of the GET methods in a controller needs to return data from the same table, but in multiple environments. All of the envrionments' schemas are the same (except login credentials/connection string). I was wondering if there is a way to use the same context and table model class to query all 3 environments with EFCore for the sake of keeping the code dry and clean. TIA
4 replies