Splitting the traffic to different areas in a ASP.NET Core 5 MVC application - webforms

I'm migrating an ASP.NET webforms app to ASP.NET Core 5 MVC. I will have 10 areas where the Views and Controllers are almost the same but with minor changes. I want to split the traffic to different areas based on the route and see how they are performing.
What feature does ASP.NET Core 5 MVC provide to split the traffic to different areas?

What feature does ASP.NET Core 5 MVC provide to split the traffic to different areas?
You can configure area routes in conventional routing to make incoming request(s) can be matched to corresponding area endpoint(s).
https://learn.microsoft.com/en-us/aspnet/core/mvc/controllers/areas?view=aspnetcore-5.0#add-area-route
Besides, if any specific scenario that requires capturing request(s) and do custom code logic to redirect to expected area endpoint based on some specific custom rules, you can try to achieve it in middleware.
https://learn.microsoft.com/en-us/aspnet/core/fundamentals/middleware/?view=aspnetcore-5.0#branch-the-middleware-pipeline
https://learn.microsoft.com/en-us/aspnet/core/fundamentals/middleware/write?view=aspnetcore-5.0

Related

MVC .NET or WEB API

We want to write a new web site for customer using SQL DB
and implement only one specific client.
what the recommended technology to be used:
Peure MVC.net
Web API and client side using AJAX
I will be glad to hear the causes, the consideration and the cost.
Thanks!
I tend to favour a web api to handle all of the database work (via entity framework), but use MVC for my front end application.
This way you have all the flexibility of an API should you want to use different frameworks in the future (Angular, ASP.net 5 etc), but you can still have the pleasure of working MVC in your front end site.

MVC WebAPI with SPA

I am new to the WebAPI. I have 4 entities:
Location
Service
Item
Application
I have read several WebAPI tutorials. They all seem to have CRUD methods in each API Controller that deals with single entity. One functionality that I need is to simulate cascade dropdown and cascade update where Location determines range of Service. Each Service determines list of Service Item. Each Item may be used in a list of Application. The question is
Do I create 4 API Controllers with CRUD methods?
I need all 4 objects on one form as List Boxes that allow multi-selection.
Along side the 4 List Boxes, how to show a list of combination of selected value that are saved to a database table?
Which javascript library or framework is the best for SPA (Single Page App)? I am currently leaning towards Backbone.js and HotTowel.js.
Thank you.
You could expose your service as an OData service. If you wish to support filtering, then you should use the separate OData NuGet package, and develop your controllers. In this case four controllers would suit.
Then, you can use a client side rich data library such as breeze.js to make building requests to the OData service straightforward. You would then use an MV* client side framework to provide two way bindings between the client side view models and the UI elements.
Hot Towel isn't a JavaScript library, it's a Visual Studio extension which allows you to create a new project as a starting point for your SPA. The template requires Visual Studio 2012 and the ASP.NET Web Tools 2012.2 update.
It uses breeze.js, Knockout.js for the binding, and Durandal.js for navigation, life cycle, and view composition.

Why is MVC used on the server? Isn't it a client-side pattern?

I'm trying to learn web development.
I understand (mostly) the concept of MVC, but I'm confused about why an MVC model is used on the server side...like Spring MVC. Isn't the server side the Model and Services, and then the client side Services, View, and Controller (AngularJS even makes that pattern explicit on the client side)?
I'm really struggling with how the MVC model fits into or facilitates server-side development.
MVC is a pattern used by much more than just web applications. Any app with a UI could use an MVC pattern.
The idea is that you have a View (html, or a window in your OS, or even a report or something), and you have a model that represents the dynamic parts of that view. Then you have a controller that is dedicated to processing input and doing the "business logic" to generate the model and apply it to the view.
So.. for example on the Server you might have this MVC pattern:
A controller receives the HTTP request and processes it.
It builds a model
The model is applied to a view to generate HTML and send it back as a response.
On the client it will be similar (but a bit different in Angular's case):
A controller is used to determine and manipulate the model.
The model is then bound to your view via directives. (Angular is really more of an MVVM pattern, but it's similar enough)
The view is similarly bound to your model via directives. (this is where the MVVM part comes in).
The idea here is that both the model and the view are kept up to date by directives.
The controller just contains "business logic" for manipulating the model.
Clear as mud?
No worries. Just know this: It's just a common pattern. It's not "server specific" or "client specific". It can be used anywhere by anything requiring data to be scrubbed into templated output.
EDIT: More thoughts.
In the case of a Web API that serves up JSON (or even XML) on the server, you're still using MVC in most cases. This is because what you're doing is:
Process the request in a controller.
Build up the model in the controller.
Render the model to a "view", which in this case is a view that serializes it out as JSON.
In the good ol' days of yore, the client side was only a display. The server was responsible for communicating with the model, applying business logic, generating a view, and sending the static, rendered content back to the client (browser).
As the web matured, some of those responsibilities migrated from the server to the client. Now, the server-side is often a thin layer like RESTful API that stores the "official" business logic (rather than convenience logic on the client) and stores the model. But for performance and user experience, the client now stores a copy of the model in its own model layer, communicating with the server and/or local storage as necessary, and having its own controllers and view logic to provide an awesome user experience.
So does MVC still apply on the server? Yes! It's just different. The server often generates the initial view from which the client-side application runs (taking localization or internationalization into account, for instance) and still houses the official model. But more importantly, the "view" in MVC just changed. Instead of the server-side view being HTML, it's now JSON or XML that the client application consumes instead of just renders.
So for functionality's sake, we still use MVC on the server. But for an awesome user experience, we use MVC on the client-side now too.

How Backbone.js with rest based service using Asp.NET MVC 4

I implemented some code using backbone.js in Asp.NEt MVC3 and found backbone.js very helpful. Actually I am developing the data warehouse application where user at view side can run/save his data analysis. And after relogin can re-run the saved analysis. On clicking the save button at toolbar system persist the analysis in DB.
My question is that can someone point links where backbone.js interacts with rest based service using Asp.NET MVC 4 so to save/retrieve the data in DB .
Please do advice me the better way as well.
I've built several very large systems on top of ASP.NET MVC4 and WebAPI, with Backbone, recently. I highly recommend WebAPI. It's very easy to use, and works very well with Backbone.
http://www.asp.net/web-api
As one example of an app that I've built with it:
https://ravenhq.com/
The registration, login, management, and account settings are all Backbone on top of WebAPI.

asp.net MVC Web API VS asp.net MVC 4 & MVC 3 internet application

i read about the beta version of asp.net MVC 4 web API , i think that it is related to building web services. So are these two frameworks (MVC 4 internet application & Web API) targeting different types of application or they may be used for building similar types of application but using different frameworks?
for example if i need to build an internet application for a registration system for a university or an internet shopping store (which i use to develop using asp.net MVC 3 internet application),, then will these two frameworks be suitable for these types of applications ???
Thanks for any help ...
BR
Those are just 2 templates. No matter which one you choose when creating the application initially you could always later change and add functionality. The MVC 4 internet application template is similar to the ASP.NET MVC 3 internet application template. It creates a default Home and Account controllers, it registers a default route and adds a couple of views.
The Web API template in addition to all this it adds an API route and an ApiController allowing you to expose RESTful APIs in your web application. The Web API is basically a simplified way to build RESTful services. Up until now this was possible with WCF but the Web API makes it really simple. The Web API could be self hosted. You don't need to put it in an ASP.NET MVC application.
The webapi makes it simple to create HTTP services. I have only used them to return json. You can use either for the types of applications you are building.
Take a look at this blog article from Scott Guthrie http://weblogs.asp.net/scottgu/archive/2012/02/23/asp-net-web-api-part-1.aspx
Web Api basically lets you create HTTP REST full services. The API also gives one full access to the http requests and responses in a type safe way.

Resources