Is Blazer server SSR and SPA? - c#

I heard that the Blazer server is SSR(server-side rendering).
By the way, I know that the Blazer server is a single page apps (SPA).
Is the Blazer server both SSR and SPA?
Then, does the Blazer server first receive data through SSR method and then receive data through CSR method to implement the SPA?

It depends on your definitions.
Blazor Server is Server Side Rendering. All the work goes on the server. It builds an html page which it passes to the client. JS client takes over, refreshes the page and then sends requests and gets bits of the page back from the server to render when they change. All the heavy lifting takes place on the server.
Blazor WASM is Client Side Rendering. The client gets a load of JS and WASM files and a small html page. It has to execute client side code to put it all together and build the page.
Both are Single Page Applications - the initially loaded page is the application. The client side code just changes out bits of the DOM to update a "page" or move between "pages".
"Pages" are components, not html pages.

Blazor has two flavours, Blazor WebAssembly and Blazor Server. Both are used to create SPAs (which are a type of application) and both can be configured to use SSR (which is a technology).
More information can be found here.

Blazor Server does Server Side Rendering, but not in the traditional way.
It only delivers a nearly empty HTML page once and from there on it acts like a SPA. Except that the logic runs on the Server and changes to the DOM are pushed with WebSockets (not HTTP). Events are sent in the other direction.
So Blazor Server has the look and feel of a SPA, to both the end user and to the programmer. You can for instance not really use cookies to store state.
But the use of server resources (per user) means it is not nearly as scalable, and you need an always-on good internet connection.

Related

How to a listen to an HTTP response from iframe?

I have a website where I use Angular for the frontend and Asp.Net Core for the backend. I have an iframe of a different website that I don't own, rendered inside the website. And after a certain amount of time the iframe redirects to the API and sends a POST request to the API. Is there a way to check when the request is completed and perhaps even get the response from the API, so that I can close the iframe or redirect to another page.
When the iframe site makes an API call to your ASP.NET Core backend, send the event to your Angular front-end. Any method of pushing events to a SPA client will work. You could create your own polling process that runs (when the iframe is first opened) or you can setup SignalR and push a server side event to the Angular client using a websocket.
There are some limited ways to communicate between an iframe and its host, but most of those require you to have access to modify the app/site that runs inside of the iframe.

Adding a web server and web pages to a .NET WinForms application

Is there a simple way to use existing .NET features to add an HTTP server to an existing .NET WinForms application that would read pre-defined HTML pages and embed some of the application's data into the HTML, ideally with Razor? This server would be accessed by clients on the local network while the application is running.
For example, imagine some application that collects data from an external device. An HTML page would be created with special markup to display the data. Multiple clients (desktops, smartphones, etc) on the local network could then access this page using a web browser and view the data.

Blazor Server: How to close browser and return a message to calling app

I recently converted my ageing asp.net webforms site to Blazor server.
One page on the site is called using a WebView2 browser control hosted in a separate net5 app. The call is made so that users of the app can purchase a license. When payment is complete the browser should return the user to the app so that registration can complete.
In my original webforms code, transfer back to a method in the app was done via a simple Jscript function:
Response.Write("<script>window.external.onbrowserclosed('" & exitmessage & "');</script>")
where onbrowserclosed is the target method in the app. and exitmessage a simple string with the results of the purchase.
I tried to rewrite this function in Blazor Server in _Host.cshtml as
<script>
function closebrowser(message) {external.closebrowser.onbrowserclosed };
</script>
calling it from a Razor component that handles purchasing:
await jsRuntime.InvokeVoidAsync("closebrowser", exitmessage);
This calls the script OK, but only if the target method (onbrowserclosed) and the message parameter are removed. When called without the target method it simply closes the browser, but obviously that's not what I'm looking for. It seems window.external is not fully supported in Blazor.
Has anyone else hit this problem ? I'd prefer to find a Blazor/.Net native alternative to call back to the app. but a JScript solution would be fine.
In the end I implemented a gRPC listener which polls my site for changes in transaction status. Not as elegant as a callback but gRPC is fast and reliable, so definitely the way to go.
If anyone hits the same issue I can provide a more detailed description.

Optionally run blazor server side

As I understand it, razor components runs entirely server side, each method call results in a signalr request to the server and the method called is executed on the server.
In blazor however, the DLLs and the runtime are shipped down to the client and methods are executed in the browser. To make a server call I now need to create an API and make standard API requests.
What I would like to know is, is it possible in blazor to generally execute everything client side as per normal, but for some methods to be executed server side? So a kind of hybrid between blazor and razor components? So doing away with the need for an API?
Razor Components is an obsolete term referring to the Component framework with which you could create either server-side Blazor applications, or client-side applications. It was unsuccessful short-lived term. Currently, the name Blazor is used to refer to the Component framework with which you can create either server-side Blazor applications, or client-side applications. This is actually how we named both kinds of application from the very beginning.
Client-side applications are executed on the browser via WebAssembly. Server-side Blazor application run entirely on the server, and communicate with the browser via SingnalR.
Front-end Blazor applications, generally speaking, require you to create a Web API on the server, and employ Ajax (HttpClient) to communicate with the server.
What model of execution you choose depend on the requirements of your application. Server-Side Blazor application are best suited for Intranet enterprise applications, while client-side Blazor applications are best suited to run across in the public Internet.
Each mode of execution have its advantages and disadvantages.
Hybrid applications, I guess, is possible, but is it, generally speaking, recommended ? When ? How ? It is too early to know... The framework is after all under construction, and patterns of appropriate coding is yet to be formulated in the course of time. But surely you can create a client-side Blazor app which communicate with Web API which exposes SignalR endpoints.(You wanted to know this, right?)
Hope this helps...

How to convert make proper React Link from source html code?

I have React TypeScript application (ASP.NET MVC Core 2.0 Server side).
Users can write html messages and post them on site.
On server side I sanitize and repair posted html to render on client side.
But if there is local links like link, targeted my React navigation components, if user clicks this link, whole site is refreshed(rerendered), but I need to act as React Link just to handle link inside React, not to rerender whole site.
How can I convert A link to React Link (on server and/or on client)?
May be there is something like PrepairLink function on client?

Categories