Base solution for your next web application
Starts in:
01 DAYS
01 HRS
01 MIN
01 SEC
Open Closed

Angular Application Publishing + Host Application Publishing under same domain in IIS? #9600


User avatar
0
olmy90 created

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)
  • User Avatar
    0
    ismcagdas created
    Support Team

    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.

  • User Avatar
    0
    lweng567 created

    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

  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi @lweng567

    Could you share the chagnes you have made ?

    Thanks,

  • User Avatar
    0
    lweng567 created

    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();
    
  • User Avatar
    0
    lweng567 created

    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");

        }
    
  • User Avatar
    0
    ismcagdas created
    Support Team