-
Notifications
You must be signed in to change notification settings - Fork 10.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Aspire launches the client of a hosted Blazor WebAssembly app on a different random port every time the AppHost is launched #59860
Comments
Server project; Properties | launchSettings.json
Since it's random, you can't determine what it will be, before creating the solution. In addition to looking in the Server project's launch settings file, how about just loading the solution into VS, hitting F5 and seeing what the URL is in the browser? |
Good morning! And thanks for your interest, @Bellarmine-Head! You might need to help me understand your second suggestion:
If I see what the URL is in the browser, it will be too late to add the address as a client of the Web API. Besides, it will be different next time the app starts up. Maybe I didn't understand what you meant. The first suggestion has got me thinking though: Your screenshot is the launchsettings.json is from a Blazor Server Project. If I could get the client to be run at the same URL as specified here, that would get me unstuck, but my WebAssembly client is being served at a different localhost port every time I boot up the app, no matter what I put in launchsettings.json. In another app, I see this working. Maybe that's the root cause of my problem. I've been doing a bit more research into this today and I'm convinced it's something to do with Aspire. The client and server of a hosted blazor web app share the same localhost address. But if you add them to an Aspire project, the server app's address (taken from launchsettings.json) is no longer the same as the client's (which is randomly generated). |
No, it won't - or shouldn't be. The port number is randomly chosen by the New Project template... which is only run once.
My screenshot is from the The current new-project template won't give you a
Weird!
It is.
uh-oh
Sounds nuts. I've never used Aspire, and hopefully never will. For all my Blazor WebAssembly web apps, the localhost port is:-
|
Yep, it's something to do with Aspire for sure. (Incidentally, I'm rather enjoying playing with Aspire, but it isn't Blazor-friendly yet, it would seem). I'm sure because:
That's the root cause. |
**EDIT: After researching the problem more extensively, I changed the title of this issue from "Question - how to know the URL assigned to a hosted Blazor WebAssembly app" to "Aspire launches the client of a hosted Blazor WebAssembly app on a different random port every time the AppHost is started".
The below is how my question was originally worded, but the root cause and the steps to reproduce are in my comment of 15th January.**
Some time ago, Bossman Dan Roth reported here, that the URL (e.g.
localhost:xxxxx
) of a hosted Blazor WebAssembly app "should be generated randomly by Visual Studio". That issue has been resolved and that's certainly what's happening on my machine. Perfect.My question is, how can I determine what URL will be (or has been) assigned by Visual Studio, please?
I either need to control the URL (set it myself in launchSettings or my Aspire AppHost) or I need to read it (from either the Blazor server project or my Aspire AppHost) once it has been assigned by Visual Studio. I don't mind which.
The use case
My hosted Blazor WebAssembly app is a client of a Web API. The client's URL should get listed in the Web API's CORS configuration. For example (in the web API)
I thought perhaps it could be set in the launchSettings.json file of the client app, like this:
But the content of that file seems to be ignored by Visual Studio when launching a Blazor WebAssembly app. Can anybody point me in the correct direction please? How do I know the URL at which my Blazor WASM app is going to run early enough in the app lifecycle that I can add it as a client of the web API?
The text was updated successfully, but these errors were encountered: