C
C#•10mo ago
slezyradosti

Blazor Server and Client app, Azure question

I have Blazor Server and Client app. I deployed it on Azure Web App (not static). When I open the created buy Azure link, client works, however I client uses wrong route for post method. How can I get the route where my Blazor Server is listening to requests?
35 Replies
lycian
lycian•10mo ago
are you using an HttpClient to post?
slezyradosti
slezyradostiOP•10mo ago
Yes
lycian
lycian•10mo ago
HttpClient.BaseAddress Property (System.Net.Http)
Gets or sets the base address of Uniform Resource Identifier (URI) of the Internet resource used when sending requests.
slezyradosti
slezyradostiOP•10mo ago
well, didn't help System.InvalidOperationException: net_http_client_invalid_requesturi blazor.webassembly.js:1 at System.Net.Http.HttpClient.PrepareRequestMessage(HttpRequestMessage ) var response = await _httpClient.PostAsync(_httpClient.BaseAddress+"Blob", content); builder.Services.AddScoped(sp => new HttpClient { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) });
lycian
lycian•10mo ago
if you set base address, everything else is relative so var response = await _httpClient.PostAsync(_httpClient.BaseAddress+"Blob", content); is wrong should be var response = await _httpClient.PostAsync("Blob", content);
slezyradosti
slezyradostiOP•10mo ago
what is a good resource to read about that? because when I read documentation, except basic things, I feel myself stupid And still doesn't work. Event input checks from Data Annotations do not work. Did I deploy it incorrectly? should I provide any code or links?
lycian
lycian•10mo ago
I assume the URI is different for the server and client, is the BaseAddress set correctly? In the remarks
When sending a HttpRequestMessage with a relative Uri, the message Uri will be added to the BaseAddress property to create an absolute Uri.

Note that all characters after the right-most "/" in the base URI are excluded when combined with the message URI. See RFC 3986 Uniform Resource Identifier (URI) Generic Syntax specification.
When sending a HttpRequestMessage with a relative Uri, the message Uri will be added to the BaseAddress property to create an absolute Uri.

Note that all characters after the right-most "/" in the base URI are excluded when combined with the message URI. See RFC 3986 Uniform Resource Identifier (URI) Generic Syntax specification.
That specifies the request behavior if you use a relative Uri
slezyradosti
slezyradostiOP•10mo ago
I did not touch it actually
lycian
lycian•10mo ago
It's hard to know exactly, it probably depends on your deployment. When you say server and client, I assumed two different web app deployments
slezyradosti
slezyradostiOP•10mo ago
One web app deployment Just asp blazor template consists of Server blazor proj and Client blazor proj So the server proj was deployed. But it calls the Client when I run it.
lycian
lycian•10mo ago
by blazor client, you mean blazor wasm?
slezyradosti
slezyradostiOP•10mo ago
It was a Blazor WebAssembly template yep
lycian
lycian•10mo ago
ahhh, hmm...I see, I was thinking slightly different For wasm I think you just always use relative paths and it "just works" unless your wasm base path isn't the root
slezyradosti
slezyradostiOP•10mo ago
to clarify
No description
No description
slezyradosti
slezyradostiOP•10mo ago
It perfectly works during debugging But for me Azure is as new as Blazor. And I can't figure out where is my problem.
lycian
lycian•10mo ago
How are you deploying? That probably has something to do with it.
slezyradosti
slezyradostiOP•10mo ago
Deployed to Web App. Deployed Server app (like from the screen above)
No description
slezyradosti
slezyradostiOP•10mo ago
Is it always so painful to deploy to Azure?
lycian
lycian•10mo ago
idk tbh, I have only done small projects. I would have assumed you had a webapi project instead of blazor server, since that has it's own page rendering. Is the wasm package deployed from your blazor server app?
lycian
lycian•10mo ago
Deploy a Blazor app on Azure Static Web Apps
Learn to deploy a Blazor app on Azure Static Web Apps.
slezyradosti
slezyradostiOP•10mo ago
I created Web App, not static one. So it should be wasm My project is as small as possible. Just this deploying thing.. I have looked though so many articles. It should be much easier. But it just doesn't work
lycian
lycian•10mo ago
Yea hang on, I'm trying this on my end to fully understand what you're doing. It seems odd to me that you're deploying both the WASM and SSR (server side rendering) to the same web app
slezyradosti
slezyradostiOP•10mo ago
I hope I didn't mislead you Anyway, I tried to deploy separately. Client to Static Web App. Server to Web App. Client was working. But not Server. And even here, I couldn't see where was my problem exactly
lycian
lycian•10mo ago
what's not working on the server? this is what I get with the base template + deploy to azure web app without changing anything https://ryzngardtest.azurewebsites.net/
slezyradosti
slezyradostiOP•10mo ago
for example: my controller action takes a model as a parameter. Data annotation is used for validating this model. Deployed app does not validate user input. And a post request from Client to Server does not work as well Did you use the same sample project as I did?
lycian
lycian•10mo ago
ah, I just did dotnet new blazorserver I didn't see you were using MVC
slezyradosti
slezyradostiOP•10mo ago
That is probably what I should have done. But I wanted to have at least some architecture in my project. Which is total mess now It is not a live/death question, you don't have to waste so much time. I though somebody would come up with an easy solution
lycian
lycian•10mo ago
eh, I'm just doing code reviews right now and answering in between I would suggest web api for server, and wasm for client or just do a new blazorserver and have it all server side
lycian
lycian•10mo ago
mvc isn't blazor, and the naming will always haunt us. mvc is asp.net. I'm asuming this is the template you did in VS?
No description
slezyradosti
slezyradostiOP•10mo ago
I started like that. But with Blazor Server... Doesn't matter. What would be different if I did like you said? Different in terms of deploying process
lycian
lycian•10mo ago
it should be the same, so I'm a little confused with you as to why what you're doing isn't working but with web api you're doing what you should: making endpoints only, not doing page rendering. All UI would be blazor wasm that's also where you would do form validation etc, in the WASM side I don't really understand the use of two UI based projects it can be done, but you're conflating ideas and usage, and that's probably causing a lot of different advice to be wrong (including my own 😦 )
slezyradosti
slezyradostiOP•10mo ago
Yeah, I wish I could go back a few days. What about routing from wasm to api? That is what I was afraid of
lycian
lycian•10mo ago
do you mean how do you set the URL of http requests? That would be the base url on the HttpClient like I said earlier. You can use specific environment app configs to make that easy
slezyradosti
slezyradostiOP•10mo ago
After deploying my routes usually go away.. Thank you for your time, Andrew Have a good day or night
lycian
lycian•10mo ago
good luck 🙂 I'll be around if you're still hitting issues. Try webapi instead of asp.net mvc
Want results from more Discord servers?
Add your server