Call a nodejs script from an asp.net Web API - asp.net

We have a REST API currently built using ASP.NET Web API and it's hosted on Azure.
One of our methods needs to compile an email template using the MJML language. Only problem is that there isn't an asp.net compiler for MJML, it's written in Node.js and none of us here know anything about node except for having used it in gulp as part of our build process.
So I guess the question is, is there an easy way (preferably on Azure) to host the node script with an endpoint that can be called from our Web API and return the compiled template.
Just to be clear, I'm not asking how to use MJML or it's compiler, just how to host a script written in Node and easy send and receive data from it. To keep this inside of Azure would be a bonus.
Many thanks.

Related

Can I deploy a svelte-kit app on php hosting without nodejs?

I am familiar with svelte.js for client side wherein client and server are disconnected and all communication is via AJAX calls. However, I have a question whether shared hosting without node installation can deploy a sveltekit app?
Any comments are welcome.
Yes and no. You can serve static sveltekit pages generated with #sveltejs/adapter-static. If you want SSR or to use server side load functions, endpoint, or any other 'backend' feature of sveltekit you will need to use a different adapter. For that, you will need #sveltejs/adapter-node, or another adapter. For supported environments see this page of the docs. So yes, you will need a javascript runtime (probably nodejs) to use all of sveltekit's features.

Blazor WebAssembly Authentication

I'm learning blazor and am having some difficulty wrapping my head around authentication. I have a .net core web api hosted and want to connect a blazor web assembly to it, but all the tutorials i find use it hosted in an asp.net core host in one package. How secure is the authentication when hosted like this on the same machine?
use Blazor WebAssembly with authentication (also if possible) is not a great idea:
usually, when you write a normal client-server application, the client collect the user typed data and send it to the server. In the server you can check if the password is correct (for example establishing a connection to a database and checking matches between username and password).
In Blazor WebAssembly, all the code is compiled, dll are generated, sent to the client (using the Web-Assembly technology) and runs inside a JavaScript sandbox. This mean that ALL the objects are available on client side and can be seen by the user, so also all the connection strings can be readed.
Also if there are some ways to mask them, none of them are 100% secure, actually.
If you don't need to have an off-line application I suggest you to use Blazor Server technology, that use SignalR.
However, if you really want to implement authentication in WebAssembly, you can take a look at the Microsoft documentation.
Hope this can be useful!
You can first go through the official docs. I also recommend you seeing this video. You'll likely need to use IdentityServer4, for that see this playlist and the official Github repo for sample projects.

Starting point of Azure WebApp

I opened a new .Net Framework WebApp and I am using it with Azure.
At the very first point, when I run the App from Visual Studio, it opens the browser and shows the default page:
I was looking for a "main" class or method but could not find one. I am wondering where does it start from? how this thing works?
If added a new method for which I want to run together with the WebApp, where should I call it from ?
I am wondering where does it start from? how this thing works?
This is about how does asp.net webapp run.When the application starts up, it runs Global.asax’s Application_Start() method. In this method, you can add Route objects to the static RouteTable.Routes collection. These will be inspected later when each request is received. Each Route object defines a URL pattern to be matched and the controller to be used in this case.
For more detail about how the Asp.net webapp run, you could refer to this article and this one.
If added a new method for which I want to run together with the WebApp, where should I call it from ?
When you publish to azure and add a new method in a controller, you could call it like yourappname.azurewebsites.net/Controllername/methodname. It mainly depend on your Rounte, you could refer to this article.
Azure App Service Web Apps is a service for hosting web applications, REST APIs, and mobile back ends. You can develop in your favorite language, be it .NET, .NET Core, Java, Ruby, Node.js, PHP, or Python. Applications run and scale with ease on Windows-based environments.
With App Service, you pay for the Azure compute resources you use. The compute resources you use is determined by the App Service plan that you run your Web Apps on.

Asp.Net core Web API calling

I am new in Asp.net Core and trying to clear my concept on web api. I have basic knowledge on web api. I can do CRUD operation using web api by running that web api project and calling it in other web application project at a time.
My problem is,
I add an web api in a web application project named "Api_BusinessUnit".
How can I call this web api in a controller named "BusinessUnitController" shown in below image. My confusion is, Both are in a same project, I can run one project at a time. So how can I use this web api in "BusinessUnitController" ?
Thanks in advance.
Why do you want to have one Web API call another in the same project? If you need to communicate between parts of your project, you can do so directly without having to over the web, which will be much better from a performance perspective and will be more reliable as well.
That said, looking at your image, I think you have two separate web projects in the same solution which isn't the same thing at all (you may wish to update your question if this is the case). To have one project communicate with the other project, you should determine the URL of the destination project and call it as you are doing. You also will need to ensure both projects are running, of course. You can launch multiple projects at once when you hit F5/ctrl+F5 as shown here:
http://ardalis.com/how-to-start-multiple-projects-in-visual-studio
For me, I am a Scott Allen fan and he explains the project structure for the particular structure you are trying to create here.
https://odetocode.com/blogs/scott/archive/2013/07/01/on-the-coexistence-of-asp-net-mvc-and-webapi.aspx
However, I am a fan of best practices and SoC, so the proper way, IMHO, is to have one solution with multiple projects and either keep the entire solution in version control, or have the project solutions separate, build and deploy to a directory will all of them for testing.
Then the key factor to running MVC and WebApi as different projects in the same solution, besides making sure that Microsoft.AspNet.WebApi.Core is installed, is that the start up project is the MVC and the WebApi references that MVC. Then you're off to the races.

Running ASP.NET from hosting process

I'm responsible for a .NET process running under windows.
The process is running as a windows service.
I would like to have the ability to be able to get some info from the service in a web browser.
For that matter I would like to write a small ASP.NET web service.
The problem is that I want the run the web service within my process.
As far as I know, I can't do that since ASP.NET must run from within an IIS.
so...my question is, is it possible to host ASP.NET server within another process?
I know that in the common scenario, I should have the "process code" run as "code behind" the ASP.NET but in my case, the .NET service is already a part of our product so in this case I'd like to have the opposite.
Thanks a lot.
You don't have to host ASP.NET inside your service. You can use inter-process communications techniques to communicate between your service and a new or existing ASP.NET webapp. Here's an example using named pipes. Or if you're using .NET 3.5 or higher you can use WCF.
If you really want the service to host its own site I don't think embedding ASP.NET is possible but you can use an http component like this one.

Resources