locked
browse from IIS RRS feed

  • Question

  • User-590375999 posted

    Hi,

    i have created single page app with asp.net web api + angular 5 , both in same project.

    when i start from visual studio the browser opens with #, 

    http://localhost:3030/MyWeb/#/

    i have deployed this project in IIS, i use the browse menu option to browse but it doesn't open with #

    http://localhost:3030/MyWeb

    so how can i configure IIS to add # in the end of the url automatically?

    Thursday, June 28, 2018 1:45 AM

All replies

  • User-1034726716 posted

    Just curious. Why do you need to #? http://localhost:3030/MyWeb is cleaner than http://localhost:3030/MyWeb/#/

    Thursday, June 28, 2018 2:08 AM
  • User-590375999 posted

    http://localhost:3030/MyWeb doesn't show the initial component but http://localhost:3030/MyWeb/#/ does show

    Thursday, June 28, 2018 2:23 AM
  • User-1034726716 posted

    Have you configured a rewrite rule for your app? See: https://blogs.msdn.microsoft.com/premier_developer/2017/06/14/tips-for-running-an-angular-app-in-iis/

    Thursday, June 28, 2018 2:41 AM
  • User-590375999 posted

    Hi,

    i have added url rewrite but still same, when i click browse it open up with 

    http://localhost/MyWeb

    Thursday, June 28, 2018 6:29 AM
  • User-590375999 posted

    Hi Vinz,

    I can disable the usehash setting in angular routing, but if i route to another component for example

    i redirect to users component from home component so the URL looks like below

    http://localhost:3030/users 

    i getting resource not found because it is looking for users controller in asp.net...

    i can't disable asp.net routing also then api doesn't work..

    Friday, June 29, 2018 4:24 AM
  • User-1034726716 posted

    Can you please post your rewrite rule here.

    Friday, June 29, 2018 10:15 AM
  • User-1780421697 posted

    May be this will help you

    namespace Angular5EmployeeApp
    {
        public class Startup
        {
            public Startup(IConfiguration configuration)
            {
                Configuration = configuration;
            }
    
            public IConfiguration Configuration { get; }
    
            // This method gets called by the runtime. Use this method to add services to the container.
            public void ConfigureServices(IServiceCollection services)
            {
                services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
    
                // In production, the Angular files will be served from this directory
                services.AddSpaStaticFiles(configuration =>
                {
                    configuration.RootPath = "ClientApp/dist";
                });
            }
    
            // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
            public void Configure(IApplicationBuilder app, IHostingEnvironment env)
            {
                if (env.IsDevelopment())
                {
                    app.UseDeveloperExceptionPage();
                }
                else
                {
                    app.UseExceptionHandler("/Home/Error");
                    app.UseHsts();
                }
    
                app.UseHttpsRedirection();
                app.UseStaticFiles();
                app.UseSpaStaticFiles();
    
                app.UseMvc(routes =>
                {
                    routes.MapRoute(
                        name: "default",
                        template: "{controller}/{action=Index}/{id?}");
                });
    
                app.UseSpa(spa =>
                {
                    // To learn more about options for serving an Angular SPA from ASP.NET Core,
                    // see https://go.microsoft.com/fwlink/?linkid=864501
    
                    spa.Options.SourcePath = "ClientApp";
    
                    if (env.IsDevelopment())
                    {
                        spa.UseAngularCliServer(npmScript: "start");
                    }
                });
            }
        }
    }

    Friday, June 29, 2018 10:31 AM