REST API with OpenRasta and ASP.NET MVC - c#

REST API Questions:
Does anyone know any good tutorial that shows how to do form based authentication with OpenRasta?
How difficult would it be to convert REST API from MVC to OpenRasta in future?
I know OpenRasta has advantages over MVC.
How about performance? Like to see some benchmark.
I am exploring OpenaRasta for ASP.NET C# app
Thanks for reading

1) No tutorial as such, if you want ot use forms authentication and you run on asp.net, that works just as usual, nothing changes much. You can still verify permissioning using the Requires* attributes.
2) Depends on you architect it. OpenRasta is resource based, MVC pushes you to be method-based, so you'll end up with systems that look and smell quite different depending on which way you go.
3) Never ran any benchmarks. The NHS, Huddle etc are all running it on high traffic sites and don't seem to have found any issues.

Related

ASP.NET MVC (Razor) vs Angular 5

We are currently considering moving from ASP.NET MVC to Angular 5, mostly because it seems like the best and latest framework. However none of us seems to be able to come up with hard reasons on why Angular is better than MVC (Razor).
SPA vs MPA seems like different approaches with neither really being better - just better at different things.
Are there any resources/comparisons with hard benefits between the two?
Update: Almost 2 years after moving to Angular 4 (currently 7) I can say that it was a great decision. Angular makes it super easy to write quite complex front-end applications and the tooling around Angular itself, TypeScript, Karma + Jasmine (unit test frameworks) is fantastic. SPA is a huge step ahead of MPA in my opinion - we can finally have fluid web experience. I never really liked Razor and the whole mess around ajax/jquery, but I can comfortably say that I am really enjoying my time now! .NET CORE 3 + Angular 7 gives us everything we need!
To anyone thinking of taking the plunge, I would strongly recommend Angular (might as well start with 8 or 9, which is current at the time of writing this).
Happy to add more details if people want them :)
6 months on from moving from ASP.NET MVC to Angular 5 (now 6) and we are extremely happy with the decision. .NET core backend and Angular frontend is a fantastic combination. It is so much cleaner and easier to create re-usable, strongly-typed, testable and easy to modify UI components!
For anyone considering if it's worth taking the plunge - I would say a resounding 'yes'!
I don't have enough points to make a comment but thought the following might help you in making a decision.
Just to note that if you use Angular CLI (The default Angular project in Visual Studio) you will lose the ability to use razor within the HTML. Something you was able to do before Angular CLI.
I do like using Angular but miss having Razor to omit certain parts of the HTML, for example, if the user didn't have the necessary roles or permissions:
#if(User.IsInRole("Admin"))
{
}
You can hide the HTML using Angular of course, but having it completely removed from the HTML itself is preferable in my opinion.
I vote for an ASP.Net MVC Web Application in the cloud [Core or whichever] , and use of razor pages as needed. That is it. Case closed.
Even if the whole world runs after Angular , Aurelia, React, Node, Strawberry, Pistachio, butterscotch JS, I will not.
After all, JavaScript is spagetti and Angular is the Flying Spagetti Monster
based on personal experience and intuitive take.
Now please don't get started about mouse hover over page areas,
What I did found out about Angular vs MVC (Razor), I can work with both :-)
Authorization: One thing to make sure is that you don't have complex authorization schemes. On the backend its easy to do your authorization on pages with Razor (even more with Core). Its more difficult to handle authorization with Angular because you will have to do it (and keep in sync) on both sides: client and server. Example: One thing you want is hide everything a user is not allowed to do. If you have a simple webapp and use a Masterpage: show only the menu items a user is allowed to see. Thats a very easy task to do in Razor. It takes more time/effort to implement this in Angular.
Templates: Razor is extremely easy to use with templates. If you develop a website that must be used a number of times but with different layouts that can be done very easily with Razor.
Maintenance: With MVC you have one application. The frontend and backend are one. For maintenance you will have a Angular frontend and X Backend, so two. That seems more costly from installation, maintenance, etc. point. If you have a simple application I would say KISS: Keep It Simple Suckers.
One: In MVC the frontend and backend belong together. That can be good or bad. If you have one application with no dependencies on other things I think MVC is a good choice.
Future proof: Angular is NO W3C and NOT baked in the browser. Because of Future proof solutions there is a strong interest in Vanilla Javascript together with Web Components. With MVC you can use this technology. Read about Microsoft FAST Design. It works great with MVC.
SPA/MPA: Thats not a point anymore. An MPA can also be flicker-free with libraries like PJAX etc.
Speed: With MVC no wait time because Shit has to be loaded. Enough bad Angular websites already exists because loading takes ages.
...: After working with Angular 9 I don't get the point of Angular. I don't know why you should go from MVC to Angular. Visual Studio has great support for MVC and is much better as VS Code. From productivity point I can produce much faster code with MVC as with Angular. If you have multiple front ends that must connect to the same backend may be then I can see the point. But even then MVC can be moduled and even can dynamically load them.
htmx Wow, now we are talking! Yes this is what we want. Let Html take back control how pages are loaded. Think this is the way to go. Worked a sample with NodeJS and are very exited about it.
Update: I just did a nodejs/express/mongodb project and it beats it all. I am an expert mvc developer, but developing faster, better on a chromebook of 220e with vs code. now I know why it's so popular. and guess what? it's free. and guess what else? part of dotnet Core is based on nodejs. the console app is the same as a nodejs server. both you will have to put behind a proxy of IIS, Apache or NGINX.
One thing that I learnt during the comparison of MVC and Angular, among various factors, is that hosting MVC application requires a compute power container like Azure Web App, docker etc, while an Angular App can be deployed in any storage like Blob, CDN etc. When Angular is built, it gives a collection of javascript files, which are perfect candidate for storage container. They do not need compute power at all, which are the most costly resource in cloud world. CDN or Blob exposes Rest API endpoint to any of its underlying resource. So, the Angular will also be exposed as an API, which is all we want.
However, angular alone will not generate dynamic web pages. We need Web-Api at back-end to give the data. This can be achieved by a server-less solution (Function Apps, Logic Apps etc) or by containerization (Docker).
One downside that I personally found that the first time load of the Page in Angular is bit slow. After that it is really smooth.
All in all, I will vote for Angular/React and .Net Core in my future Web projects.

Choosing the proper C# Project (Active Directory)

I have recently started an internship in a big company (4.5k employees) which uses an Active Directory and have an intranet web app allowing them to handle all types of services, going from administration to user creation etc ... It was developped in 2004 and now they want to remake the whole application, well actually I have to make it. And kind of on my own, I am the only developer here.
I was thinking of developing an ASP.NET MVC 5 project to develop this application, do you think that is a good choice? Don't know many other design-patterns for this, and I found on the web that Active Directory is accessible using ASP.NET MVC, and everything seems compatible. The old project used a hand made architecture, which didn't respect any design-pattern and using mainly VBScript. I want to use C#, that's the only imperative I guess.
Thanks for your help, I hope this is clear, if not I will try to make it clearer :D
ASP .Net MVC seems to be a good choice. You can use ADAL for authentication and manage any kind of AD data. Here are some links:
Http://www.ianatkinson.net/computing/adcsharp.htm
But you must master ASP.Net MVC (Bootstrap / razor / ...)
Good luck !

REST Web Services using MVC, is it a good idea?

In .Net, I think about a web service as being a project type that you select from the menu, define your classes and methods then .Net does all this black magic under the hood to allow someone on the other side of the world to reference my web service and start coding using my classes and methods directly within their visual studio.
So having this preconceived notion, when looking at writing REST web services using MVC 3 (I know MVC 4 has a REST api baked in but am waiting for a full release) I'm wondering all the usual stuff like "is this a good idea", "will this stand up to heavy use" and "am I just writing toy web services that other developers will laugh at".
Now I think a lot of my anxiety is probably down to microsoft not having wrapped a big, overly complicated, bloated, shiny REST package around it yet. So I'm looking to have my anxiety relieved hopefully by people telling me yes MVC web services are perfectly good things to create.
Any help?
I've done it a few times, I am still using it in production and haven't got any complaints.
I actually think its a nice solution because it so simple to setup and maintain.
Not this incredibly xml-configuration-heavy wcf stuff..
You might want to also have a look at the WebAPI stuff that is in the process of being released (.net 4.5):
http://weblogs.asp.net/scottgu/archive/2012/02/23/asp-net-web-api-part-1.aspx
It's very much to do with exposing plain html services.
I would suggest you take a look at ServiceStack: http://www.servicestack.net/. It 's not only quite mature, but it can help you produce cleaner code.
It really does depend on what you plan on doing with your application. Yes, you could write an MVC website that doubles as a RESTful service. However, you are then tying your UI layer very closely to your logic layer, and that is what you really need to consider. I am working on an MVC site with a ServiceStack REST service (already mentioned by #Ioannis) . The reason that I did not make MVC my REST service is because I did not want any changes in my UI to potentially affect any third party application that might be using my logic service. So, as long as you carefully consider the ramifications of making your site also your RESTful service, then either decision could be ok. :)
As others have mentioned here, ServiceStack provides a solid, terse REST Web Services Framework allowing you to effortlessly develop typed, idiomatic C# API's end-to-end.
ServiceStack also includes a number of high-performance components that deeply integrates with ASP.NET MVC using the ServiceStack.Host.Mvc NuGet package.
To learn more about the benefits ServiceStack can add to your MVC project see:
http://www.servicestack.net/mvc-powerpack/

Needs help in defining architecture of ASP.Net web app?

I just got a project to be build up from scratch. Its front end will ASP.Net and Backend is SQL 2008. The requirement is, the architecture of the app should be such so that we can have access to app from any computers(desktop, laptop, netbooks) as handheld devices as well like smartphones, PDA's, Tablets. Also it should be plugable in nature like FB and orkut. That is in future if the client needs to attach games or third party applications, then it should be plugged in without rewriting the entire thing again. Also client needs the entire web ajaxified either using the toolkits or JQuery.
I have prior experience of ASP.Net webforms applications with tiered arcitecture. So this time keeping his all needs, i am thinking of a web app with WCF Service. But i have no idea or experience about the pluggable architecture with SOA and MVC (all three). It seems if I implement all the stuffs, it will going to be a mamoth of codes. For pluggable arch I googled and found MEF on codeplex. So finally I came up with the following things :
ASP.Net MVC
MEF
JQuery
WCF
RESTful with AJAX
XML
Guys, i really need your help, I am unable to think how to place all these stuffs together. Or is there any other best alternative you can suggest for.
Also, there is one more requirement by the client is that he want the loose coupled code, that's reason i chosen MVC, the aspx page can only have the controls and required HTML, validation and other codes should be done in the Business Layer of the app.
it will be great help.
You should take a look at Orchard: it's an ASP.Net MVC CMS system that is very pluguable. You can add a lot of functionnalities through modules, and there are a lot of modules already implemented and accessible.
Even if you do not end up using Orchard itself, taking a good look at its architecture should be a very good starting point for your app, as Orchard responds to a lot of the same requirements you have, and as it is an open source project, you can get as much inspiration from it as you want.

Lightweight .NET web development?

I'm currently working on a project that has a sizable amount of both client and web code. The client code is written in C# and the web piece is written in PHP. Maintaining consistency between the two worlds is becoming cumbersome, and I want to consolidate the web code to .Net.
The issue is that I hate web development in ASP.Net Web Forms. I want something as raw as PHP, just using C# instead. I've read a little about ASP.Net MVC, but it looks like it abstracts too much of the request logic for my liking.
Does anyone know of a lightweight way to allow C# + .Net to handle web requests? Should I be looking more closely at MVC?
Update: I went with ASP.Net MVC and I've been very pleased so far.
If you're looking to get away from ASP.NET Web Forms, the I recommend ASP.NET MVC with a custom view engine (like Spark, or NHaml). This will give you the consolidation your looking for and allow you to avoid most of the Web Forms that your not happy with.
AFAIK, to do .NET web development, you are going to have to interact with ASP.NET in some form or another, but the custom view engines in MVC could be exactly the abstraction your looking for.
It is now possible to use a software stack completely separate to IIS and ASP.Net using Kyak, Nancy and Gate.
http://bvanderveen.com/a/gate-0.1.0/
You might want to check out Kayak, which is, to my knowledge, the only standalone .NET web development framework that's not ASP.NET.
Caveat: Kayak's request handling implementation is not the best, so there may be performance or scaling issues. I can't say for sure -- I've only read it, not run it.
Edit: I've taken another look at the source code, and it looks like they've rewritten a significant portion of their server code, and in doing so fixed the major issues. Performance probably won't be a problem.
MVC.NET is open source, so you can make it do what you want. It is a framework that is overrideable, extensible, etc. I'd look closer at it. It works great for me and I've come from a background of CGI, Struts and Webwork. I love it.
In my opinion nothing is more lightweight than the combination of NancyFX (http://nancyfx.org/) with Dapper (https://github.com/SamSaffron/dapper-dot-net) for data access.
NancyFX can be hosted within ASP.NET, WCF, Azure, OWIN-compatible environments, Umbraco or you can write your own host.
Read also these articles:
http://theothersideofcode.com/lightweight-development-in-dot-net-nancy
http://theothersideofcode.com/lightweight-data-access-in-dot-net-massive
I also suggest you to TinyIoC (https://github.com/grumpydev/TinyIoC) for decouple your application layers.
Regards,
Giacomo
You should look into the IHttpHandler and IHttpModule interfaces. These are the foundations for ASP.NET WebForms. Brad Wilson has a good intro to the former.
In the bad days when WebForms was the way to do ASP.NET development I was writing my own simple MVC framework with these interfaces. The bit I struggled with at the time was the View engine but now there are a number of these.
You take a closer look at ASP.NET MVC since the source is available and decide for yourself. It may be that you want to change some of the conventions used rather than the whole framework.

Categories