I started a new application using the template for Angular and .netcore, created a web app, installed swagger, and deployed it to Azure, the application isn't much different from the template as I have just started adding my HTML to it. I am now trying to access the APIs but I get redirected to index.html, on localhost I am able to access it on a different port, the one SPAproxy starts before redirecting me, is there a way to expose this port on an Azure Web App? or even better can I expose it on the same port so I just use /swagger to access it?
Asked
Active
Viewed 314 times
0
-
What is the .Net Framework you are using ? – Harshitha Dec 08 '22 at 03:29
-
Please share your `Program.cs` and `appsettings.json` file. – Harshitha Dec 08 '22 at 03:31
1 Answers
0
Check the below steps to create .NET Core Web API
and Angular Application to run within the same Port.
Here instead of Angular + .NET Core Template, I have added the 2 projects in the new folder and running the App.
- Create a new folder.
- In
Visual Studio
,Create a.NET CORE Web API
within the newly created folder. - Add another project
ASP.Net CORE Web App
with in the same project. - Open the
command prompt
with newly createdCore Web App
root folder(to create angular). - Create an angular application by running the below command.
ng n mynewAng
- In
command prompt
navigate to the newly created angular root folder(mynewAng).
cd mynewAng
- Run
ng serve --open
to launch the angular Application.
In
Angular
project =>angular.json
, change theoutputPath
to"../../Your.NetCoreAPIFolderName/wwwroot"
Deploy the Application to Azure App Service.
In
Azure Portal
=> YourAPI Management service
=>API's
=> click on yourAPI
underAll API's
=Test
My Program.cs
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddControllers();
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();
var app = builder.Build();
if (app.Environment.IsDevelopment())
{
app.UseSwagger();
app.UseSwaggerUI();
}
app.Use(async (context, next) =>
{
await next();
if (context.Response.StatusCode == 404 && !Path.HasExtension(context.Request.Path.Value))
{
context.Request.Path = "/index.html";
await next();
}
});
app.UseDefaultFiles();
app.UseStaticFiles();
app.UseHttpsRedirection();
app.UseAuthorization();
app.MapControllers();
app.Run();
OutPut

Harshitha
- 3,784
- 2
- 4
- 9