Hi,
is it possible to publish Angular + ASPNET Core Application Publishing + Host Application Publishing under same domain /site in IIS? In your doxc (https://docs.aspnetzero.com/en/aspnet-core-angular/latest/Deployment-Angular-Publish-IIS) it is published to separate sites.
Prerequisites
Angular + ASPNET Core
Angular + ASPNET Core Application Publishing + Host Application Publishing under same domain in IIS?
6 Answer(s)
-
0
Hi @olmy90
Yes, that's possible. We are hosting AspNet Zero's demo in that way. If you are developing your app separately, you can download a new project with the same name as your existing project and select Single solution while downloading the project.
After that, you can take a look at Startup.cs. It contains a inline middleware code to redirect all 404 responses to index.html. In that way, both ASP.NET Core app and Angular app can be hosted in the same IIS website. You can move this code into your existing application.
-
0
Hi,
I followed your suggestion making changes to the start.cs. But it always shows the swagger index.html. I then manually enter
localhost\index.html, i can get the login screen, then i got a bad request when i tried to login. It failed on /api/TokenAuth/Authenticate
Please advise thanks Laurie
-
0
Hi @lweng567
Could you share the chagnes you have made ?
Thanks,
-
0
Hi,
This is what I have in the Startup.cs file.
public void Configure(IApplicationBuilder app, ILoggerFactory loggerFactory) { app.UseAbp(options => { options.UseAbpRequestLocalization = false; }); // Initializes ABP framework.
app.UseCors(_defaultCorsPolicyName); // Enable CORS!
//======= added the following line to run angular and .net core in single Site
app.Use(async (context, next) => { await next(); if (context.Response.StatusCode == 404 && !Path.HasExtension(context.Request.Path.Value) && !context.Request.Path.Value.StartsWith("/api/services", StringComparison.InvariantCultureIgnoreCase)) { context.Request.Path = "/index.html"; await next(); } });
// ==============
app.UseStaticFiles(); app.UseRouting(); app.UseAuthentication(); app.UseAbpRequestLocalization();
-
0
Hi,
I later figured out that in the one solution template, there is no HomeController. There is a HomeController in seperate solutions template.
In the HomeController, the Index has redirection to swagger. public IActionResult Index() { return Redirect("/swagger");
}
-
0
Hi @lweng567
You can either delete the HomeController or modify it like this https://github.com/aspnetzero/aspnet-zero-core/blob/dev/aspnet-core/src/MyCompanyName.AbpZeroTemplate.Web.Host/Controllers/HomeController.cs