Extend ASP.Net MVC Website with IronPython - c#

is it possible to extend an existing ASP.Net MVC Website, written in C#, with IronPython. I want to make our website customizable. So my plan was, i can write additional controller and models in IronPython and views with "cshthml" and then load it dynamically in the website.
I've searched a lot and found some examples, but they always work with ASP.Net Web Forms.
Thank you!

These two pages found on Google help explain it in depth.
http://www.tikalk.com/net/write-aspnet-mvc-using-ironpython-resources
http://forums.asp.net/t/1527861.aspx?how+to+start+ironpython+in+asp+net
You will need to add a reference to the DLL in your references section of the project. Other than that, things should work as normal. I use IronPython in my business website without any issues whatsoever. If you get it running and find that there is a piece of code you are having trouble with, please don't hesitate to comment.

Related

Is it at all possible to migrate ASP.NET ASPX solution to ASP.NET Core 2.0?

I want to migrate my asp.net (UI ASPX pages WebForms) application to ASP.NET Core 2. By some search I found out aspx is not supported in .net core. If this is true(anyone has exact documentation for this?) how should anyone proceed to convert from pure asp.net aspx project to asp.net core 2.0?
I used portable analyzer tool but it is confusing to just give every .dll file and get report which is more confusing.
Please give valid Microsoft document if possible.
It all depends on what you mean by "migrate". As mentioned in the comments to your question, ASP.NET Core does not support web forms so there isn't any way to just automatically convert an a Web Forms website to an ASP.NET Core website.
That said, it is possible to make the migration. I have been working to do just that for a very large web forms based website that I want to convert to ASP.NET Core. If you are serious about making the journey, then here is some info that will probably help you.
The general architecture of ASP.NET Core is based on MVC so it's much more similar to ASP.NET MVC than ASP.NET Web Forms. So you will end up rewriting pretty much all of your UI code using some derivative of a MVC pattern. Instead of master pages you will be using layouts. Instead of server controls you will be using tag helpers. Instead of user controls you will be using partials and view components. Instead of code behinds you will be using controllers and view models. Etc.
It's worth noting that there is still an http context object, request object and response object and they are extremely similar to the analogous objects in web forms. So that helps with the conversion.
Also to make the conversion process easier, you can build an ASP.NET Core web application that targets the full framework. This means that you will have access to most everything you are use to in the full framework except anything in the System.Web namespace. Targeting the Full framework does mean that your new website will only run on windows. But if you can live with that (at least for now) it will make the conversion process easier for you.
If, in your old website, you broke out a bunch of the functionality into class libraries, that will make your life easier. You should be able to bring those class libraries over to the new website unchanged and reference them from the ASP.NET Core website and they will most likely work fine provided they don't reference System.Web. Any code that does reference System.Web will need to be modified to use the new analogous objects or UI approaches.
So in the end, you may be able to bring over your data models, data access code, business objects, and business logic without too much hassle. But you will have to do a total rewrite of your UI related code. That's the journey I'm on and it's not as hard as you might think, at least not once you get up to speed with ASP.NET Core in the first place. Go get `em!
I found an article claiming that it's possible somehow.
As you know it's not easy to migrate entire project from WebForm to .Net Core instantly. So what if I be able to have my web form pages working on production and at the same time start to convert pages one by one gradually? I mean there are the combination of two approaches at the same project.
It's the idea that an open source named DotVVM proposes. You have your ASP.Net web form pages and merely install DotVVM through Nuget. DotVVM supports both approaches. DotVVM contains similar controls like GridView, Repeater, FileUpload and more, you need to know about DotVVM syntax though.
DotVVM can run side-by-side with other ASP.NET frameworks (Web Forms, MVC, Razor Pages)
it's claimed that:
If the business layer is separated properly, rewrite on one page takes about 1 hour in average.
After a few months (if your project is large), when all the ASPX pages are rewritten in DotVVM, you will be able to create a new ASP.NET Core project, move all DotVVM pages and viewmodels into it and use them with .NET Core. The syntax of DotVVM is the same on both platforms.
Here you can see five steps needed for the migration.
You can transfer all your business logic, models and even some controller methods (You just need to adjust those ActionResult to IActionResult). If you're using Ninject (for ASP.NET Framework IOS), you just need to register them to your Startup.cs. Basically, what I'm trying to say, you need to create a new application under .NET Core. It would be changes in the actual project solution, but your actual business flow won't be different. I hope this helps you.

asp.net core 2.0 dotvvm vs razor pages - which one is more powerful for an interactive web app?

With the latest release of ASP.NET CORE version 2.0 we now have Razor Pages which I really like because it shows a MVVM way of developing which I am already familiar because I've used it in UWP.
I was searching to develop web apps without js because I am a .net developer and I came across this framework known as DOTVVM , it is great because it gives some features of js frameworks like Angular, React etc. and it also integrates very well with ASP.NET CORE 2.0
I want to discuss this between following 3 scenarios :
I should use DOTVVM and not use JS at all.
I should use Razor pages instead with asp.net core 2.0, because razor pages provide all functionality which dotvvm provides and it will have more community in future.
I should learn a JS framework like Angular or React because neither razor pages, nor dotvvm is powerful enough to replace them.
The discussion can be from point of view of all developers, so I can get opinion of JS developers as well as those who have worked with dotvvm or Razor pages. The aim is to create completely interactive and responsive web app with good performance.
**Important : ** the web app created can be a progressive web app from the start or maybe turned into a pwa after creating it, depends on the technology I choose at the end.
I know for a progressive web app I will need to write a little JS, but that is alright considering that is very simple and little to write.
The reason of this question is so that we can discuss these options from multiple perspectives and deduce a better option at the end for my app.
It really depends on the type of the application you are trying to create. The fact is that you can build any application in any web technology. The difference is only in how difficult it would be.
Razor Pages are very easy to use and they are part of ASP.NET Core platform. They are using the MVVM pattern, but they are not helping with client interactivity. If you need to hide some form field based on some condition, you would need to do it in JavaScript.
I would use them for a simple company website, very simple admin sites with few pages and trivial forms, or for a public facing part of some eCommerce site. I would probably use also jQuery or other libraries to do the interactivity, animations and things like that.
DotVVM is an MVVM framework which helps especially with web applications with complicated UI: lots of complex forms with dozens of fields and interactivity (when you select an item in a combobox, another combobox will get new values, some fields will be pre-filled, a part of the form will disappear or change and so on). Modal dialogs, multi-step wizards, lots of grids with data, sorting, paging...
Because DotVVM handles many things for you and translates the data-bindings to JavaScript, you don't need to write the JS yourself. It doesn't mean that you should not learn it. It will help you a lot if you know it - you will be able to add even more interactivity, extend the framework when you need it and more. DotVVM lets you do quite a lot without knowing JS, but you will get much further if you know it.
Angular, React or other client-side frameworks are used widely today and many websites and applications are built in that. They are more universal than DotVVM, which aims primarily at the business app segment and requires .NET on the server (because it is not only the client-side library).
Using Angular or React requires the knowledge of JavaScript, and not only that. You will need to know Node.js and the related tooling, like npm. You will need to exchange data with the server, so you will need to build probably a REST API, use Swagger to generate the client-side proxy classes, and then you will probably need some other JS libraries with controls and things like that.
It is quite a lot of things to learn and if you are used to the comfort of Visual Studio, like the IntelliSense or the debugger, you will miss these features for sure.
And finally, you don't need to stick to one technology. You can combine Razor Pages with DotVVM for example. You can make the admin dashboard in DotVVM and the public part of the website in Razor Pages.
Microsoft is coming back to the WebForms approach to simplify the project structure trusting in the "Convention over configuration" mantra, while hiding the configuration from developer to make things faster. But it has the disavantage that everything will be mixed again. I doesn't look like a smart move for organizing. But... Hey! Something new must catch the attention of the dev towards Microsoft.
If your page uses an MVC Web API for the REStful, it's really more easy to just use Razor pages. If not, I would recommend you to use Core MVC.

When to use Web Api in MVC

(First i just want to say i'm sorry if its not worded the best but i have been researching for hours and i thought maybe someone on here could clear this up for me)
Im new to creating web apis and i have been googling just doing some research and i have built a few MVC applications just to get exposed but i never really thought of making an API for it until today. One of the reasons its listed to be useful is it allows your application to be used across tablets and smart phones etc. What im not understanding is how you would do this as in would you just add something to the API so it makes it compatible for all browsers or if i need to re build it using Web API instead of MVC.
Thanks,
I think your looking at a Web API from the wrong perspective. It's not really about compatibility necessarily, but rather about the ability to reuse the code/back-end functionality.
So rather than having your dependencies all wrapped up in one MVC project, the references are external. This allows for essentially the same functionality across multiple projects as long as the request are being handled in the same manner.

How can I implement the same models and data across ASP.NET and Windows Apps

Bit of a beginner question, but I'm currently building an ASP.NET MVC web app and I would like to transfer my models and data across to a Windows Universal App to begin with and then maybe a Xamarin app in the future.
Are there any good tutorials or blog posts out there that anyone can recommend that would help me. The idea is that the user will have the same experience across web and mobile so I don't want to hard code models for each client.
To do this you will need to split your domain model into different projects.
When you create your MVC application create a new C#/VB.NET assembly and place all of your models in the assembly. This way you can reuse the code across multiple projects.
Keep in mind that you shouldn't just dump code into this assembly take the time and create a proper namespace structure so that you don't confuse yourself or anyone else later on down the road.

webmatrix c# and razor

I wanted to give a try to razor but there are not many tutorials on web; I've already tried this one, so better ask here. Can anyone please tell me how razor works? I mean are there any code behind pages or controls? and what is done in code behind pages if they exist? Also, how can I reference code behind pages? Generally speaking, what type of code fits in the cshtml page, I mean, for the sake of a clear design how should be the structure etc etc. finally, any good tutorial is highly appreciated. Thanks!
Please note: I'm not using visual studio, I'm using webmatrix.
I can't speak a whole lot to WebMatrix. But...are you familiar with ASP.NET MVC? Given what you're asking, it sounds like maybe you aren't. I would start with learning the basics of MVC first. I learned on the NerdDinner example
http://weblogs.asp.net/scottgu/archive/2009/03/10/free-asp-net-mvc-ebook-tutorial.aspx
To answer your question more directly, no there are no code behind files (though a code behind is technically possibly through some hackery). The paradigm is completely different from web forms. Essentially you have classes called controllers that accumulate the data for a page. The "data" for the page is referred to as a model and closely resembles what your problem domain is. Models are classes intended to represent objects in the system (customers, users, orders, widgets, etc...). The controller passes models to the view. The view renders the page. So the code you'd expect to find in each of these is:
Model: object representing the problem domain like Blog, Person, User, etc...
Controller: Gets data from database using services that return Model objects (or calls into entity framework, NHibernate, whatever)
View: displays that using cshtml, aspx or whatever the ViewRenderer is
So, in your view (cshtml), you're really just going to have straightforward programming for displaying UI elements and performing UI logic. You'll have mostly HTML and then some bits scattered around to pull data from the model and display it like
<td>#Model.Name</td>
<td>#Model.Description</td>
Hope that helps
EDIT: After reading a bit more, sounds like WebMatrix is kind of a RAD tool for web apps. Looking at the tutorial that you posted, looks like they're showing you go treat it like classic ASP and put everything right on the cshtml page. This is an option. I wouldn't recommend it though. It'll make life tough, but I'm unsure if there are better ways in WebMatrix.
Razor is a view engine, which can be used by itself in Razor pages (.CSHTML/.VBHTML) or in ASP.NET MVC. If you use it by itself, it's kind of like writing classic ASP or PHP, where the code is all inline. No code-behinds. Here's a brief introduction to the syntax:
http://www.mikesdotnetting.com/Article/153/Inline-Razor-Syntax-Overview
That site also has a lot of other great articles about the nature of Razor.
create App_Code folder put cs file to this folder
convert App_Code to dll in bin folder then upload bin folder
(by visual studio 2012/publish web site)

Categories

Resources