How should I embed Blazor server-side into an existed asp.net core project? - asp.net-core

I made a blazor server-side project for submitting the form.
In spite of there is a tutorial of Microsoft about how to embed it in asp.net core(https://learn.microsoft.com/en-us/aspnet/core/blazor/components/integrate-components?view=aspnetcore-3.1). However, I am about to embed it not only in one website but also in some other. So this way is so troublesome.
There is another way by using Iframe. Whereas Iframe does not support CSS vh units well and it has some other limited(such as samesite attribute/cross-origin).
Is there any way to solve this? Thank you.

I suggest you could consider build it as an Templated components.
You could create a component library. And then you could use this template in each project.
Details, you could refer to this article.

Related

Creating new razor views after compiling and publishing an asp.net core app?

Is it possible to create new razor view pages after you have compiled and published the app? For example:
A function that runs a cli command like dotnet new page or dotnet new view?
Trying to create an application that will have a web gui that will allow for the creation of new pages. I can do this with scripting languages, but I'm unfamiliar with how to do this in asp.net core. Any suggestions will be greatly appreciated.
It possible, but we don't suggest you do such things.
As far as I know, asp.net core is build based on C# and is a compile language. We don't suggest you compile and publish it at server side.
As you know after you use the command, you need to have some permission for this application and the backend code logic may have more permission, it will caused a lot of security problem.
If you want to create a new page, I suggest you could consider using the Js and html page to do the same things.

Is it feasible to convert an single MVC razor view/page into a SPA?

I currently have an ASP.NET Core MVC application with multiple pages with one particular page having a lot of hand-made javascript code and ajax requests. It's becoming quite hard to manage and I would like to move to a framework like Angular, React etc for this particular page only. It is feasible to convert a single MVC view to a SPA app and still keep the other pages? Does anyone have any references on this? Google is not being too helpful...
The simplest way I have found to do this is to use one of the SPA templates and then add the static pages around that.
Here's an an example project I have made that demonstrates the concept by adding a new Razor Page to the angular SPA template.
To do this for an already existing MVC/Razor Pages app I would suggest copying the following from an SPA template project to the MVC/Razor Pages app:
ClientApp
Controllers (SampleDataController.cs)
Views (Home, Shared)
npm_shrinkwrap.json
package.json
tsconfig.json
webpack.config.json
webpack.config.vendor.json
Startup.cs (copy the SPA things)
This is not an exhaustive list but should get someone most of the way.

How can I use PHP files as views in Durandal?

My problem is I want to integrate Durandal witha Wordpress site yet Durandal expects HTML files as views. How can this be changed to use PHP files?
Yes. A php script generates dynamic HTML files on the server. You would just need to generate HTML that is valid within the context of Durandal.
The strategy is similar to using Durandal with ASP.Net, which would be a good place to start looking for tutorials.

Integrate Orchard CMS with MVC4 Website

I already have MVC4 website and that is to perform Searching (OPAC). Now, We have to integrate it with Orchard CMS. I have followed the procedures to add my existing solution into Orchard CMS solution. Everything is okay but I am not able to get the javascript to work with my view page.
Also, The default Orchard library to include js extensions ie, #Script.Require or #Script.Include also not recognised as intellisense feature in my view page.
When I use default MVC library to include the js like #Scripts.Render is not working as expected.
How can I make my custom javascript to work my page.
Help me to identify the problem.
Thanks

Can we use Razor on an existing ASP.NET 4 website?

Is it possible to use Razor on an existing ASP.NET 4 website?
Yes, you can use Razor with an existing ASP.NET WebSite. Simply open your website using the WebMatrix tool and start adding CSHTML files.
One caveat is that if your website is using WebForms controls the WebMatrix tool will not provide any help working with them in existing aspx pages. Additionally, Razor does not support WebForms so you will not be able to add something like <asp:GridView> to a CSHTML file.
You shouldn't even need to open the site in Web Matrix if you already have VS2010 and MVC 3 (which includes the Visual Studio tools for building ASP.NET Razor websites) installed. Installing MVC 3 makes the libraries required for developing Razor pages available, even to existing web applications.
See:
http://www.asp.net/webmatrix/tutorials/program-asp-net-web-pages-in-visual-studio
You don't need to create a new Web Pages site (as per the instructions). You can just open up an existing web site, right click the site's root folder, click add item and you should see "Web Page (Razor)" as an option.
Inellisense and debugging works in the Razor pages just like the Web Forms pages
As stated above, keep in mind that ASP.Net Web Pages (Razor) and ASP.Net WebForms are really different platforms, and the reusable components of each can not (or at least should not) be used
marcind is correct, if you want to open your existing ASP.NET website in WebMatrix and work on it from within the tool. If, on the other hand (or in addition to), you want to use Razor syntax in your site and stay within VisualStudio, check out this article: http://weblogs.asp.net/rashid/archive/2010/07/10/use-razor-as-asp-net-mvc-viewengine.aspx
There are four things you need to do:
Add References to the Razor assemblies installed with WebMatrix. These can be found at C:\Program Files\Microsoft ASP.NET\ASP.NET Web Pages\v1.0\Assemblies
Create a custom ViewEngine class, a View class that inherits from IView (not that hard, check out the source in the article above)
Add your new ViewEngine in Global.asax Application_Start()
ViewEngines.Engines.Add(new RazorViewEngine(("cs"));
Create your view pages with a .cshtml extension, instead of .aspx
There are a few steps here, but it's quick work, and the source from the article above will get you a long way there.