0

I have multiple angular application inside an asp.net core application. Now I want to set one of them as default. Let say When I run the app, it automatically goto angular home application. Solution structure: SQL-> EntityFrameworkCore->.NET Core->Angular application( HomeApp, App1, App2....)

Right now, after I run the application, I have to go to URL and type : localhost:5000/home Togo to Angular Home application. Otherwise, it won't show anything.

I tried with asp.net core Map and UserSpaStaticFiels. In each angular app1, app2 index.html file I setup <base href="/home/">

And in startup.cs the code I setup like this:

<i>
 // For each angular application we want to host:

            app.Map(new PathString("/home"), home =>
            {
                if (env.IsDevelopment())
                {
                    StaticFileOptions clienthome = new StaticFileOptions()
                    {
                        FileProvider = new PhysicalFileProvider(
                                Path.Combine(Directory.GetCurrentDirectory(), @"home"))
                    };

                    home.UseSpaStaticFiles(clienthome);
                    home.UseSpa(spa =>
                    {
                        spa.Options.SourcePath = "home"; // spa.Options.StartupTimeout = new TimeSpan(0, 5, 0);
                        spa.UseAngularCliServer(npmScript: "start"); // it will use package.json & will search for start command to run
                    });

                }
                else
                {
                    // Each map gets its own physical path for it to map the static files to. 
                    StaticFileOptions clienthome = new StaticFileOptions()
                    {
                        FileProvider = new PhysicalFileProvider(
                                Path.Combine(Directory.GetCurrentDirectory(), @"home/dist"))
                    };
                    // Each map its own static files otherwise it will only ever serve index.html no matter the filename 
                    home.UseSpaStaticFiles(clienthome);

                    // Each map will call its own UseSpa where we give its own sourcepath
                    home.UseSpa(spa =>
                    {
                        spa.Options.StartupTimeout = new TimeSpan(0, 1, 30);
                        spa.Options.SourcePath = "home";
                        spa.Options.DefaultPageStaticFileOptions = clienthome;
                    });
                }
            });
 </i>

My expectiation is : asp.net core should run only home application whenever I start visual studio without go to url and tyle localhost:5000/Home.

1 Answer 1

0

Since the apps all have base hrefs it seems the cleanest approach would be to just add a redirect from / to /home. Maybe something like...

app.UseRewriter(new RewriteOptions().AddRedirect("/", "/home"));
Sign up to request clarification or add additional context in comments.

1 Comment

Hey @Pace, thank for your answer. I tried it, however, when I start localhost:5000, it still returns 404.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.