Multiple WebApp projects within the same solution - c#

I currently have a VERY large webapp project, a DAL layer and a BLL layer and two testing projects in a solution together. I would like to start moving away from ASP.NET webforms and begin moving over to MVC4 with Razor.
I have tried going down the hybrid project route by adding in the correct routes, folders and project guid's into the csproj, but, this seems like a bit of a hack.
Is there a way i can have a Webforms project and a MVC4 project within the same solution, and have them play nicely together when deployed. I.e. if one cannot handle the request given, the other tries to handle it. This way, i am free to migrate the webforms project to MVC over time.

Is there a way i can have a Webforms project and a MVC4 project within
the same solution, and have them play nicely together when deployed
With ONE ASP.Net and VS 2013, you can make Webforms, MVC and Web API play together pretty nicely. Check out this reference.
if one cannot handle the request given, the other tries to handle it.
There is no IN-THE-BOX solution for dynamic switching between MVC and webforms. You have to use concepts like HttpModules or HttpModules or Routing etc., to get to have customized request handling.

Related

Integrate Angular with MVC in existing ASPX project

We have an existing Application in ASP.Net (Aspx Pages), we are thinking to integrate new functionality in MVC. This is something that we can easily do it through the several examples available on the Internet.
Here, the main question is "What if we want to integrate MVC project with Angular?" We could not find any example or blog related to the same.
Is it possible? What are the pros and cons of it? How we can achieve it?
We are totally blank in this, any help would be appreciated.
Note: We do not have any code because we haven't found anything.
You have to consider following things at least:
Routing (Angular has its own routing configuration which can be tweaked if needed).
Angular (not AngularJS) uses TypeScript. So, in your existing ASP.NET project, you have to ensure that your TypeScript files are transpiled into JS.
Since you say that the existing ASP.NET project is working, it might make sense to think about why you would like to do this, what your objectives are.
AFAIK, using Angular in ASP.NET project directly (without using MVC alongside) makes more sense.
I think you can do the following:
Use Angular for client-side rendering, calling HTTP
APIs and UX. Angular allows re-usable components written in TypeScript and makes architecture modular.
Continue with ASP.NET for server-side processing and security.

Creating a Project in VS19 to work with an Angular Frontend and ASP.NET Backend

I am trying to set up an Angular8 project to work with an already existing WCF Service and ASP.NET backend. The goals being to get the project set up in Visual Studio 2019. In addition to getting the actual project set up how to then communicate to the WCF Service from the Angular Project to receive the data?
I have tried various tutorials but most of them use ASP.NET Core instead of just ASP.NET. I have gotten far with setting up a test project with a ASP.NET MVC application then forcing it to route to Angular but that is still posing some problems. If someone has some advice for setting up the Angular project to work with just an empty ASP.NET project that would best. None of the test projects I have created thus far are exactly what I am looking for, so posting them here would just cause confusion.
Expected: A demo project to prove that a project can be set up where Angular8 can communicate to the WCF Service, get some data from it then display it.
You can try to use ASP.NET Boilerplate Framework: https://aspnetboilerplate.com/ this framework starter templates for both types of ASP.NET projects: Core and MVC.
ASP.NET Boilerplate (ABP) is an open source and well-documented application framework. It's not just a framework, it also provides a strong architectural model based on Domain Driven Design, with all the best practices in mind.
I believe that is a good way to start. Also you can create project using either: Angular, Vue or React.
Hope that helps you. Good luck!

Best practice webapi/website in one project

I am creating a new website and web api. Using the VS2013 template I select the webapi template (with individual login). The template creates a mvc asp site.
Is there anything wrong with having my website in the same project as my web api or should I create two projects in my solution. One for the API and one for the website?
I am thinking of allowing a desktop app to use the api as well.
As Brian said there is nothing wrong, but it is not only about code organization, if you host them in same project then there is no need to enable CORS for API if you are building SPA (issuing XHR requests from browser), they both will be on the same domain.
As well from security perceptive it will get complicated because you will use cookies for the MVC application and bearer tokens for the API. I'm not big fan for the VS 2013 Web API template with individual accounts because it add lots of middle wares and boilerplate code that you might need to use or not aware of its functionality.
My recommendation is to separate them from the beginning and have control on both projects.
You can read more on how to build API from scratch and components you need here.
No there is nothing "wrong" with including the WebAPI code in the ASP.NET MVC project. At its simplest, having the WebAPI in a separate project is merely code organization, having any code in another project is about code organization. If your project is small, will remain small, and you are the only one working on the project than it really is fine to leave API in the same project as the ASP.NET MVC website.
However, if you expect other people to work on the project, if you expect the code base to grow. Than you should organize your code well from the start and place the WebAPI in a separate project.
But for a shorter answer: it is wrong, you should always be tightly organizing your code at every moment or it will get out of control, be disorganized and hard to maintain in the future.
So put the WebAPI in a separate class library project.

ASP Classic functionality with ASP.NET MVC

I have a current site written in classic ASP VB and I would like to upgrade it and I have been working heavily in ASP.NET MVC 3.
I would like to find a solution to get a system that works with both CLASSIC and ASP.NET.
Is there a way to develop a new system in MVC and navigate in and out of CLASSIC and back into MVC workflow?
If so, whats the best way to achieve this?
Your biggest issue is state. In ASP, chances are you threw a lot of crap into the Session object. ASP.NET (MVC or web forms) and ASP do not share the same session (state), so you end up having to store state somewhere to have it continue to work.
As long as you can get a place to store the state that both ASP and ASP.NET MVC can both consult, you can start migrating the pages piecemeal. If you cannot figure that out, you will have to scrap the ASP after you completely rebuild the site in ASP.NET MVC.
NOTE: I have been leading migrations (ASP >> ASP.NET (both flavors) and VB >> VB.NET). Unless you absolutely have to use a mixed mode, you are better to rebuild and then migrate the site over rather than rely on a mixed site. The worst thing that can happen is somebody stored something stupid in session or application, that you did not envision, and you are now in a place where you are not keeping something important. And you probably find it after a user complains about some transaction they did that did not migrate and now you no longer have any information about it.
NOTE 2: Sometimes clients want to migrate piecemeal and refuse to listen to you stating it is a bad idea. Your option, at this time, is move on to another client (or job) or do it. If "do it" is the option, make sure you have your butt covered, as this is a minefield.
Based on my experience, the answer is no.
The problem between ASP and ASP.NET are that their Core are completely different. For example, there is no way to share their Session values because they work completely differently.
The only workaround I could see would be to put the shared information between the two technologies in the database for the other to consume, but that's dirty since that information is only temporary.
If you don't need the identification or any other information shared between the two other than persistent information, you can include an ASP file anywhere is a ASP.NET MVC solution. Visual Studio will try as hard as possible to give you IntelliSense (but it won't work between ASP and ASP.NET modules) and IIS should be able to execute the VB code in the ASP file. When you switch from a technology to another, you include a certain ID in the address.
If it's not your case, the best way at that point is either to keep the project as legacy in a ASP project which may work very well for many years if some standards are well implemented or to switch entirely the project to a ASP.NET project and start from scratch.

Architecture for new ASP.NET web application

I'm maintaining an application which currently is just a web service (built with WCF) and a database backend. The web service is built in layers with a linq-to-sql data access part with core functionality in an own assembly and on top of that the web service assembly which contains the WCF code. The core assembly also handles all business logic rules (very few actually).
The customer now wants a Web interface for the application instead of just accessing it through other applications which are consuming the web service. I'm quite lost on modern web application design, so I would like some advice on what architecture and frameworks to use for the web application. The web application will be using the same core assembly with business rules and the linq-to-sql data access layer as the web service.
Some concepts I've thought about are:
ASP.NET MVC (or MVC-2)
Webforms
AJAX controls - possibly leting the AJAX controls access the existing web service through JSON.
Are there any more concepts I should look into? Which one is the best for a fresh project?
The development tools are Visual Studio 2008 Team Edition for Developers targeting .NET 3.5. An upgrade to Visual Studio 2010 Premium (or maybe even Ultimate) is possible if it gives any benefits.
Definitely dig into ASP.NET MVC2.
All of our projects are now being developed using ASP.NET MVC2. It's not just highly scalable. It's highly testable as well. Which leads to way better maintainable apps in the long term.
WebForms vs. MVC2 points - (speaking out of experience):
Scalability:
In our company we had a lot of applications using WebForms which then were updated and changed by us as needed by our customers.
I think your customer will be requesting more changes on the application in near future. Making calls to other services, and maybe you'll have to rework parts of the final product to match their wishes.
And with the upcoming Cloud Computing and the Windows Azure platform you'll probably need to keep up with your code.
ASP.NET MVC absolutely supports the concept of being able to scale up your application any time you want.
I remember one of our customers walking up on me asking me for an extension for their app (they have a member management system) and the feature would contain something like a link to export the current view as a csv file so they could do office stuff with it (mostly serial letters).
It wasn't really a big problem setting that feature up. (took around 2 hours including writing tests) - let's go to tests:
Testability:
Using WebForms we didn't really have much interest writing tests because it was a pure pain to do so.
I remember writing some tests to have at least some proofs but let's drop that topic.. (:p)
We had tests for our custom classes but we couldn't really test all the EventHandlers within the WebForms.
Our CodeBase is way cleaner and saver to use thanks to this testable environment. I just check out some of the code, modify it, run all the tests and: Oh, it broke on strange behavior! - Let's fix that again. Earlier, I remember sitting with my co-worker debugging and trying to find those bugs for hours.
With ASP.NET MVC2 we are now lacking tests!
We ask all kinds of people (even the non-Web ones) to provide test-cases we could feed into our TestSuite.
And yeah, there are some AJAX-Controls too:
AJAXability:
You asked about AJAX Controls and in conjunction with ASP.NET MVC I highly recommend you to check out Telerik ASP.NET MVC UI Controls.
If that isn't something for you, we also make extensive use of jQuery and jQuery UI
With ASP.NET MVC and the HTML Views, those libraries aren't just a pleasure to use, they just look amazingly beautiful.
There is no random-html-tag-id-value autogeneration anymore!
But what I like most is: You can finally really re-use your code again.
There is so much more to those frameworks than just that, there is the T4 templating system. Auto-Scaffolding for your ViewModels / DomainModels with the Html.EditorFor() method and of course there is a great and easy way to use the IoC and DI paradigms.
Assuming that you have asked the question with mostly .NET Framework related tags, you'll probably stick with it.
Just to keep the post complete, there are also other frameworks that are just as good (or even better):
Ruby on Rails
Django
CakePHP
And many many more!
There's also DynamicData which may be appropriate if you need simple CRUD access to your data.
The Web Service Software Factory (WSSF) might come in handy in your situation.
This will allow you to define your contracts (XML entity returned (if XML you choose), etc.) while designing the server/client communication using WCF (or standard Web Service communication protocol).
WSSF favors either ASP.NET MVC or ASP.NET MVP. A simple example of the MVP architecture is shown here, plus this article.
As for me, I often come with a hybrid-like architecture using a bit of both MVC and MVP, as both have different strong points which combined together fill each other's improvement points.
I'd also recommend looking into Silverlight.
http://www.silverlight.net/learn/
Just my opinion to use MVC on Client sites and WebForms inside administration pages(site)

Categories