Quantcast
Channel: Active questions tagged blazor - Stack Overflow
Viewing all articles
Browse latest Browse all 4839

How to stop Hosted Blazor WASM from navigating to api

$
0
0

I have designed my blazor wasm application and its hosted in blazor server app, therefore both applications share the same base url. When i launch my server app, it successfully launchers the wasm app. My problem is that when i hit the refresh button on the web browser , the api/server app loads in the browser instead of refreshing the blazor web assembly. How can i stop this?

This is my Server Startup classpublic class Startup{public Startup(IConfiguration configuration){Configuration = configuration;}

    public IConfiguration Configuration { get; }    public void ConfigureServices(IServiceCollection services)    {        services.AddRazorPages();        services.AddControllersWithViews();        services.AddEndpointsApiExplorer();        services.AddSwaggerGen();        services.ConfigureCors();        services.ConfigureIISIntegration();        services.ConfigureLoggerService();        services.ConfigureMySqlContext(Configuration);        services.ConfigureRepositoryWrapper();        services.AddAutoMapper(typeof(Startup));        services.AddControllers();        services.AddRouting(options => options.LowercaseUrls = true);    }    // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.    public void Configure(IApplicationBuilder app, IWebHostEnvironment env)    {        if (env.IsDevelopment())        {            app.UseDeveloperExceptionPage();            //app.UseSwagger();            //app.UseSwaggerUI();            app.UseWebAssemblyDebugging();        }        else        {            app.UseHsts();        }        app.UseBlazorFrameworkFiles();        app.UseStaticFiles();        app.UseHttpsRedirection();        //app.UseCors("CorsPolicy");        app.UseForwardedHeaders(new ForwardedHeadersOptions        {            ForwardedHeaders = ForwardedHeaders.All        });       app.UseRouting();        app.UseAuthorization();        app.UseMiddleware<ApiKeyMiddleware>();        app.UseEndpoints(endpoints =>        {            endpoints.MapRazorPages();            endpoints.MapControllers();            endpoints.MapFallbackToFile("index.html");        });    }}

My WASM Program.cs file

public class Program{    public static async Task Main(string[] args)    {        var builder = WebAssemblyHostBuilder.CreateDefault(args);        builder.RootComponents.Add<App>("#app");        builder.Services.AddScoped(sp => new HttpClient(new AddHeadersDelegatingHandler())        {            BaseAddress = new Uri(builder.HostEnvironment.BaseAddress)        });        builder.Services.AddAntDesign();        builder.Services.Configure<ProSettings>(builder.Configuration.GetSection("ProSettings"));        builder.Services.AddScoped<IChartService, ChartService>();        builder.Services.AddScoped<IProjectService, ProjectService>();        builder.Services.AddScoped<IUserService, UserService>();        builder.Services.AddScoped<IAccountService, AccountService>();        builder.Services.AddScoped<IProfileService, ProfileService>();        await builder.Build().RunAsync();    }}

Viewing all articles
Browse latest Browse all 4839

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>