Is deploying to a hosting provider required for standalone Blazor webassembly PWA? - asp.net-core

I am working on a Blazor(PWA) standalone app. Is deploying to a hosting provider required for standalone Blazor webassembly PWA? Or is it possible to serve the app from a network location for users to download and run it locally in their browser? I looked for documentation but can't find any. Please let me know. Thanks!

You'll need to host the app from an HTTP server that provides secure hosting (HTTPS). For example, you could set up an HTTP server on your local network, or use a hosting provider on the internet.
It cannot be shared from a network drive, or anything like that because it's not considered secure, and thus the service worker won't be registered.

Related

The web server (IIS) fails to load static files (css, js, images) over HTTPS

I am hosting my website with a hosting service provider. The website loads perfectly when the request is HTTP (i.e. http://example.com), but the web server (IIS) fails to load static files (css, js, images) over HTTPS (i.e. https://example.com), I get "Failed to load resource: the server responded with a status of 403".
I checked this link CSS, Images, JS not loading in IIS and it says maybe I need to set the identity of the anonymous user to the App Pool Identity. The problem is that I asked my hosting service provider to perform that task, but the provider told me that they do not do that on application pool identity because this increases security leaks with impersonating authentication.
I am using .NET 5.0 and I tried to modify the launchSettings.json file to allow anonymousAuthentication, but that didn't work, do you know what else can I do to solve this issue?
Summarize from the comments:
The problem was caused by hosting firewall. Migrated the website to another hosting provider, then the problem is gone.

How to enable HTTP endpoints for Redirect Url in AzureAD?

I've got Azure ServiceFabric web-app (AspNetCore 3) hosted over reverse proxy (NGinx). The app use AzureAD (in company) authentication. I've Registered App for the AD and setup Redirect Urls mannually in manifest. After publishing the APP and configuring DNS and reverse proxy I tried to authorize to my app but failed with AADSTS500117: The reply uri specified in the request isn't using a secure scheme.
Is it possible to configure client to allow http redirects?
P.S. As I know Identity Server allows it by configuring DiscoveryPolicy.
P.P.S. You can find more information in my origianl question (see. How to change redirect_uri for Azure AD)
What happens?
when you deploy web apps with a reverse proxy, as is, for instance the case with App Services as Linux containers, your application will be called on an HTTP address, whereas its registered redirect URI in the app registration will be HTTPS.
This means that when a user browses to the web app, they will be redirected to login.microsoftonline.com as expected, but with redirect_uri=http://<your app service name>.azurewebsites.net/signin-oidc instead of redirect_uri=https://<your app service name>.azurewebsites.net/signin-oidc.
How to fix it?
In order to get the right result, the guidance from the ASP.NET Core team for working with proxies is in Configure ASP.NET Core to work with proxy servers and load balancers. You should address the issue centrally by using UseForwardedHeaders to fix the request fields, like scheme.
The container scenario should have been addressed by default in .NET Core 3.0. See Forwarded Headers Middleware Updates in .NET Core 3.0 preview 6. If there are issues with this for you, please contact the ASP .NET Core team https://github.com/dotnet/aspnetcore, as they will be the right team to assist with this.

Host two asp.net core applications on the same Ip and port (localhost:8080 for example)

I have two projects which are ASP.NET CORE servers (1 BackEnd and 1 Identity Server)
I would like the BackEnd to serve both apps on the same port and keep two separately runable projects.
How can I make this possible ? The purpose is to open only one port to the client.
Thanks in advance
I have two projects which are ASP.NET CORE servers (1 BackEnd and 1 Identity Server) I would like the BackEnd to serve both apps on the same port and keep two separately runable projects.
If your App(s) are hosted on IIS, you can try to deploy your BackEnd service and Identity Server in two separate applications under same web site as below.
Please note that the application's path would become part of the site's URL if we create an application in IIS. To make your Apps can work well, you may need to modify some code to include application's path in URL while you configure Identity Server to protect your BackEnd service.
In IIS, you need to set a binding for each web application. Then each web application will respond to requests for the corresponding binding.

Host Asp.net Core Web Api locally

I am learning Asp.net Core Web Api. I need to access the api from a flutter application but am not ready to host the api on Azure. What are my options if I want to host the api locally on my computer so I can access it from another application like my Flutter app client, and is there any tutorials I can follow to learn how to implement the solution.
There are several ways to go about this, here are some options:
FROM VISUAL STUDIO: You can simply run the ASP.NET Core Web API from Visual Studio in Development Mode by Pressing F5
FROM COMMAND PROMPT: Run the API Project from the command line by opening a command prompt window in the root project folder of the project and use the dotnet run command. See here for more info about the command: dotner run command
HOSTING IN IIS: I am assuming you are running a windows OS. You can turn on IIS and its features. Simply follow the instructions on this page: Host ASP.NET Core in IIS on how to deploy ASP.NET Core to IIS. The advantage of this is that you have the application always running while you work on your flutter application locally.
I hope this helps you resolve your situation.
What are my options if I want to host the api locally on my computer so I can access it from another application like my Flutter app client, and is there any tutorials I can follow to learn how to implement the solution.
If your application is developing now, there is no need to host the application and let the Flutter app client to access. We could build some json file as the right format like web api response to develop the client app.
If your client application and web api has now developed successfully, you want to host the web api to let fluent app or other application to access from internet. You should have a public IP address and host the application on IIS or else. Public IP address you should ask for the IP provider company. Without a public address, the client side app couldn't access your application from internet.
If your web api and the client app are in the same intranet, you could let the client app directly access the web api after the web api hosted on IIS by using hosting server's IP address.
About how to host the asp.net core application on IIS, you could refer to this article.

Azure Application Gateway with API as a backend pool is not working

I have .net core API inside the web app and that web app is backend pool for azure application gateway. while trying to access the web app got below error.
"502 - Web server received an invalid response while acting as a gateway or proxy server."
On app GW, health prob for that web app in unhealthy but while access the API as a https://abc.azurewebsites.net/api/values then it works.
When we deploy API in Web App Service then apiname.azurewebsites.net does not work give any probes to application gateway and treat unhealthy. API works like xxx.azurewebsites.net/api/values and Application Gateway also know this path. We have to put /api/values in override backend path of http settings. Same have to do in health probes.
Yes, you can first verify if the backend API could access directly without app gateway. Then this error may happen due to the following main reasons:
NSG, UDR or Custom DNS is blocking access to backend pool members.
Back-end VMs or instances of virtual machine scale set are not responding to the default health probe.
Invalid or improper configuration of custom health probes.
Azure Application Gateway's back-end pool is not configured or empty.
None of the VMs or instances in virtual machine scale set are healthy.
Request time-out or connectivity issues with user requests.
Generally, the Backend healthy status and details could point it out and show some clues. You could also verify all of the above reasons one by one according to this DOC.