Unable to host blazor Webassembly authentication app in IIS
I've created blazor webassembly app :
using visual studio 2019
new project => blazor webAssembly app => Authenticatin type : Individual accounts
checked Asp.Net hosted check box
I did not change anything just used the default template
Its working fine in visual studio and I can register , login and logout successfully
but when hosting on IIS failed with the following error :
Error: Could not load settings from '_configuration/MyWebstie.Client'
at a.createUserManager (http://mywebsiteaut.com/_content/Microsoft.AspNetCore.Components.WebAssembly.Authentication/AuthenticationService.js:1:5887)
Note : I already installed (aspnetcore-runtime-3.1.18-win-x64.exe) and (urlrewrite2.exe)
Any help please, I am stuck on this
Internet Information Services
Blazor
-
AgaveJoe 28,536 Reputation points
2021-08-17T13:52:26.647+00:00 It seems the client is configured as the application entry point. The server is the application and hosts the client.
-
shaker ismaeel 1 Reputation point
2021-08-17T14:36:19.633+00:00 Thanks to reply AgaveJoe
but I already have the server project as startup project -
AgaveJoe 28,536 Reputation points
2021-08-17T17:26:09.377+00:00 Are you sure? The error message indicates the client. And this is the exact error message that appears when trying to access the client directly.
-
Farid Uddin Kiron MSFT 456 Reputation points • Microsoft Vendor
2021-08-18T01:22:10.797+00:00 Could you please share your code, so that it can be reproducible?
-
shaker ismaeel 1 Reputation point
2021-08-18T05:57:51.437+00:00 Yes I am sure , its working fine when you run from Visual Studio
Butt the issue appears when you host to IIS -
shaker ismaeel 1 Reputation point
2021-08-18T06:25:06.577+00:00 Thank you Farid Uddin Kiron MSFT
I am using the default template from Visual studio as I said on the questionusing visual studio 2019
new project => blazor webAssembly app => Authenticatin type : Individual accounts
checked Asp.Net hosted check boxI am not able to attach the project here seems not allowed to attach zip files
Your attachment must be one of: xml,gif,png,jpg,jpeg,pdf,txt,log
-
Farid Uddin Kiron MSFT 456 Reputation points • Microsoft Vendor
2021-08-18T06:28:42.627+00:00 You don need to upload files, just share code snippet so that we can reproduce the issue. Full project is not required.
-
shaker ismaeel 1 Reputation point
2021-08-18T06:53:43.27+00:00 Here is
appsettings.json{ "ConnectionStrings": { "DefaultConnection": "Server=(localdb)\\mssqllocaldb;Database=aspnet-TestAuthToIIs.Server-6D93E526-0E18-4693-8ED4-5FBBDBA67976;Trusted_Connection=True;MultipleActiveResultSets=true" }, "Logging": { "LogLevel": { "Default": "Information", "Microsoft": "Warning", "Microsoft.Hosting.Lifetime": "Information" } }, "IdentityServer": { "Clients": { "TestAuthToIIs.Client": { "Profile": "IdentityServerSPA" } } }, "AllowedHosts": "*" }
-
shaker ismaeel 1 Reputation point
2021-08-18T06:54:30.997+00:00 Client program.cs
public class Program
{
public static async Task Main(string[] args)
{
var builder = WebAssemblyHostBuilder.CreateDefault(args);
builder.RootComponents.Add<App>("app");builder.Services.AddHttpClient("TestAuthToIIs.ServerAPI", client => client.BaseAddress = new Uri(builder.HostEnvironment.BaseAddress)) .AddHttpMessageHandler<BaseAddressAuthorizationMessageHandler>(); // Supply HttpClient instances that include access tokens when making requests to the server project builder.Services.AddScoped(sp => sp.GetRequiredService<IHttpClientFactory>().CreateClient("TestAuthToIIs.ServerAPI")); builder.Services.AddApiAuthorization(); await builder.Build().RunAsync(); } }
-
shaker ismaeel 1 Reputation point
2021-08-18T06:55:08.73+00:00 Server program.cs
public class Program { public static void Main(string[] args) { CreateHostBuilder(args).Build().Run(); } public static IHostBuilder CreateHostBuilder(string[] args) => Host.CreateDefaultBuilder(args) .ConfigureWebHostDefaults(webBuilder => { webBuilder.UseStartup<Startup>(); }); }
-
shaker ismaeel 1 Reputation point
2021-08-18T07:02:06.6+00:00 Let me know if you want to share more files
-
Farid Uddin Kiron MSFT 456 Reputation points • Microsoft Vendor
2021-08-18T07:21:13.433+00:00 I think you haven't configured your URL rewrite option for Blazor app. It requires a additional settings. You need to install URL rewrite module and need to follow these steps here . Let know if you have any further assistance.
-
shaker ismaeel 1 Reputation point
2021-08-18T12:19:00.957+00:00 I have URL rewrite module already installed
I followed the steps you pointed but did not help me
I believe the issue is with authentication (Individual accounts) its working fine on Visual Studio but failed on IIS
While when creating a hosted webassembly project without authentication (Authentication type : None) its working on both cases Visual studio and IIS , the issue seems to be hosting authentication app in IIS -
Farid Uddin Kiron MSFT 456 Reputation points • Microsoft Vendor
2021-08-19T01:45:47.11+00:00 Would you kindly try allowing both anonymous and windows authentication together and then try if same problem persists then install
Microsoft.AspNetCore.Authentication.Negotiate and include this line on ConfigureServices services.AddAuthentication(NegotiateDefaults.AuthenticationScheme).AddNegotiate();
Let me know your update.
-
shaker ismaeel 1 Reputation point
2021-08-19T13:54:47.487+00:00 Is it needed to add certificate to the project to make it work on IIS ?
-
Farid Uddin Kiron MSFT 456 Reputation points • Microsoft Vendor
2021-08-20T01:51:47.953+00:00 Did you able to implement the steps accordingly?
-
shaker ismaeel 1 Reputation point
2021-08-23T08:34:47.357+00:00 I tried the steps
Would you kindly try allowing both anonymous and windows authentication together and then try if same problem persists then install
Microsoft.AspNetCore.Authentication.Negotiate and include this line on ConfigureServices services.AddAuthentication(NegotiateDefaults.AuthenticationScheme).AddNegotiate();with no Luck ,
I tired in 4 different machines with same result
Would you please create the template project in your side and check if you can reproduce the issue?
I mentioned the steps that I did in main question -
Farid Uddin Kiron MSFT 456 Reputation points • Microsoft Vendor
2021-08-24T01:22:07.74+00:00 Is the problem still persist?
-
shaker ismaeel 1 Reputation point
2021-08-24T06:41:02.82+00:00 Yes , the problem still persist
-
shaker ismaeel 1 Reputation point
2021-08-24T09:17:50.337+00:00 Is it needed to add certificate to the deployed app?
-
Farid Uddin Kiron MSFT 456 Reputation points • Microsoft Vendor
2021-08-26T01:21:37.977+00:00 Its not required though but if there is any physical restirction on your environment then might required. So no obligation for certificate in general.
Sign in to comment