How can I restructure my site without a conversion to MVC/WCSF? - asp.net

I have a portfolio made in C#/ASP.NET which started off small but, as it is selling myself, it has grown in size very quickly.
I started off with using ASP.NET webforms model but this has meant that some of my code is in class libraries (.dlls) and some in page codebehind.
I want to fix this (no defined stucture), but without the overhead of migrating to ASP.NET MVC or WCSF.
How could I address these problems? I am thinking of moving all logic to WCF services and calling them from page codebehind. Is there a better way?
EDIT: The current problem is codebehind (used only as the site was small at the start but now it gets a lot of attention from me with updates). I want to seperate this all out so it's easy to test (what MVC addresses), and the coupling is generally low. Is it enough to use WCF to achieve this? What other techniques could I employ? Maintainability is another concern because maintaining a codebase split between .dlls is awkward (when debugging, as I noticed and mentioned in some previous threads).
Thanks

Unfortunately, traditional web forms applications are damn near impossible to test. WCF won't be of much help because it's a communications technology that will help you to get the data to codebehind classes but won't help you to render or test pages.
Due to this complexity, there are very few test automation tools, and the few there are are commercial paid-for products. One such tool I have heard of, but have not used personally, is Ivonna. You can also test using browser automation. Two great tools to help with this purpose are watin and WebAii.
This is, of course, dependent on whether you still want to keep the original code lying around. What I take in when I read your post is that you want all of the benefits of MVC. Unfortunately, it may be best to take the plunge and rewrite the application. It's painful, I know, but the sheer amount of hackery to make WebForms ape MVC concepts is overwhelming, to say the least.

I cant fully imagine what you need, but consider URL redirection / slug

Related

implementing ASP strategy in ASP.NET

I've built several database driven web sites with ASP and I'm trying to migrate the basic functionality to an ASP.NET architecture.
I want to have each link in my navigation tree correspond to a different function that will step a user through various requests and provide sequential database driven responses and possible follow-up questions. I typically do this in ASP by using the query string to execute different parts of the code in an SSI file. Each link in my navigation tree basically calls a different SSI file.
In ASP.NET I think I have a pretty good handle on web form basics, data binding, site navigation tools and master pages, but I'm having trouble with the overall design picture.
Do I want to have each link redirecting the user to different pages? My understanding is that ASP.NET is much better at maintaining state information and so I shouldn't have to rely on the query string to keep passing values to an SSI file to do sequential parts of each task.
Should I be using BLL and DAL to do this and/or stored procedures and managed code? Or could I do this sort of thing more simply with ASP.NET web pages, as opposed to web forms?
Feedback that would include a reference article and/or web example would be greatly appreciated. Thanks!
You don't necessarily have to abandon your whole way of thinking and take up ASP.NET Web Forms.
I've been making sites with ASP.NET Web Forms since it came out in 2001. But I think ASP.NET MVC would be an easier transition for you. I mean, some things are more difficult in MVC than in Web Forms. But on the whole, MVC will promote more web friendly practices and it's what I prefer now.
For example, the whole idea of postbacks and viewstate in Web Forms certainly makes a lot of things easier. But they also have a problem of hurting SEO and breaking the back button. MVC doesn't rely on any of this and it's easier to refine the user experience with the way form posts, redirects, and URLs are handled.
I wrote an article awhile back comparing MVC vs Web Forms...
http://swortham.blogspot.com/2009/10/when-to-use-aspnet-web-forms-and-when.html
Based on what I'm seeing, it looks like you've got wizard-style navigation across multiple ASP pages, and you want to have wizard-style navigation in an ASP.NET (WebForms not MVC) site.
If I'm misunderstanding this, I'll gladly delete this answer.
I'd recommend the Wizard control, (Video demos available all over the place) which will provide such an interface in one page, reducing a lot of the complexity. there's no need to keep track of variables across pages - it's all in one page, and therefore always accessible.
Wizard pages do tend to have a LOT of code and markup, but the trade-off is that all of the wizard functionality is in one pace, not scattered across files, and it's inherently obvious what's happening at each step. With the multiple-file approach, a maintenance developer needs to trace which page posts to which page and spend more time understanding the design.
The article on MVC vs Web Forms was quite interesting, although after looking at a few training videos I got the impression that the coding is quite a bit different from ASP. (Most of the examples I also see involve C#, although I have seen a few with VB, which is preferred since I'm already learning a lot of new things in a short time.) Also, I wonder if MVC will let me use the validation tools, which will be quite necessary in a different aspect of this project that involves several different and quite long forms. Given that I've invested a fair amount of time in learning about ASP.NET, I'm wondering if I should just go the extra mile (or two) and learn how to create business objects (BLL) and a data layer (DAL).

Web applications - combine or separate?

For our company I'm creating a big Extranet website which will feature a set of sub-applications. I'm a bit puzzled by what should be the right setup of the solution and projects.
I have one web application that we call the Portal. It contains the authentication/authorization classes, masterpages, navigation/url routing classes and theme definitions. It will also contain some basic overviews for our customers to get a quick idea of their project status.
In the coming year we are going to develop and integrate more applications with the portal. Think of it as detailed overviews and tools called Feature A, B and C. Over the years we will improve these applications and release new versions. These web applications should fit into the navigation of the Portal seamlessly. I'd like them to reuse the masterpages and themes.
What is the proper way to setup this solution?
How can I tie the applications together, re-use the master pages and keep it maintainable?
How can I share certain webcontrols (ASCX) in a proper way?
We are using TFS, perhaps any branching/merging ideas?
Edit:
I'd like to create it in ASP.Net WebForms, we have the most experience in that area. But basically we can use anything, we've got the webserver under our own control (as long as it is Microsoft oriented, not switching to php or something like that :))
What is the proper way to setup this solution?
The proper way... There are so many. I have seen a lot of applications, and a lot of different setups (a lot of which that I would deem "proper"). What you're really asking is for the best way for your situation.
Because you're building a portal, you'll have the luxury of feature separation which will help you as you develop additional features for your application.
I would setup a single website with a separate folder for each feature. Making it a single website will allow all features to share the same masterpages, usercontrols, and configuration file - without having to do anything special. (On that note, I would put all your master pages in a folder by themselves, and create another folder for your usercontrols).
How can I tie the applications together, re-use the master pages and keep it maintainable?
Again... folders are the best option here. Folders will help separate each feature, making the application easy to manage.
How can I share certain webcontrols (ASCX) in a proper way?
First of all, ascx files are not webcontrols. They are usercontrols. WebControl is a class for creating server controls that reside in a separate assembly. Regarding usercontrols, as I said above, if you put them in a separate folder, they're always in one place and available throughout the application.
We are using TFS, perhaps any branching/merging ideas?
There really isn't anything special you need to do here. There are a lot of different paths you can take regarding branching:
One is to create a branch for every release.
Another is to create a branch for every new feature you add (in your case, this is pretty much the same as the first option).
Yet another is to create a branch for each developer.
When I decide how I am going to branch my code, I think about what will protect me the most. In your case, you need to plan for bug fixes in between feature releases so maybe one branch after each release makes the most sense (call it your dev branch). Given the separation of features, though, one feature may not effect the rest of the application. You may not need this kind of branching to be safe.
As Brian says when making an API public you should commit to it as much as possible, which means it should change as little as possible after the initial release. However to make something that stable requires lots of effort up front so if you aren't ready to commit to the API you should instead internalize it as much as possible and for that reason you might want to combine things more than separating them.
However, I'm not going to suggest an architecture that fits your application based on a 5 paragraph description. What you need to do is to weight pros and cons of having a few big projects vs. having a bunch of loosely coupled small projects. I mean, the more planning you do up front, the easier you will have it down the line, provided you stick with the plan.
So contrary to Brians answer, I wouldn't recommend you make your entire system "as loosly coupled as possible", only that you make it as loosly coupled as it needs to be. ;) Loosely coupled code can cause as much trouble as tightly coupled code, if you are abusing it.
See:
1. What is better, many small assemblies, or one big assembly?
2. Specific down-sides to many-‘small’-assemblies?
In the end, only you know how much you want to focus on each of the "...bilities", maintainability, extensibility, reliability etc. So get your priorities and goals straight and plan accordingly.
Regarding branching strategies you could read the TFS Branching Guideline 2.0 which have a good introduction to various branching strategies ranging from basic to advanced. Even if you don't use TFS this is a good guide to read (I use SVN at the moment). Since I currently work in small teams with 1-4 devs, I tend to use a strategy that is between basic and standard. Not that I'm recommending this for you, but that whats works best for our team.
As for sharing code between projects. In SVN we can use "externals" which means that the shared file will appear in several folders so when you change one copy and commit the change to svn, all the other copies will be updated on the next svn update. However, I can't remember if TFS have something similar.
Note: Beware of externals in SVN... they can cause... problems. ;)
My advice is to try to avoid sharing aspx, ascx and master pages as much as possible. It usually hurts a lot more than it helps. Instead try to use inheritance or other alternatives to achieve your goal.
ASP.NET MVC 2.0 has a concept called "Areas" where you build subsections of an application in isolation from the rest. As far as I know these areas can be maintained in separate projects from the "main" application. It sounds a lot like what you are requesting so maybe you should look into that.
Hope it makes sense. ;)
I would look at making your system as loosely coupled as possible. As/when you add more applications, your website will become less and less reliable (since no component will be up 100% of the time, combining these will reduce your overall reliability). So you should build your system to cater for the non-major services being down (I believe the Amazon homepage, for example, has 100-ish services contributing to it, and as such it's built to be fault-tolerant)
Your APIs between services should remain as stable as possible, such that the implementations can change without breaking the coupling. You should also investigate automated testing of this at the web level (perhaps Selenium or similar?) since testing the individual services will give you little coverage re the overall behaviour.
You might find it useful to look at implementing a custom VirtualPathProvider. On my last project we had multiple ASP.NET sites which needed to share theme files (master pages, user controls, images, style sheets) so I created a VirtualPathProvider which allowed us to map a virtual folder (e.g. /Themes) to any physical folder on the hard drive (e.g. C:\Shared\SiteThemes).
It's not trivial but didn't take too long and hasn't caused any problems. Incidentally it turned out to be a great way to overcome the maximum component limit in WiX... Note that you can't precompile sites that use a VirtualPathProvider.
Use MVC Concepts from now. they give more extendability and flexibility for a robust applications.
You might look at using SharePoint. It's a pretty decent platform for ASP.NET application delivery, particularly if they coexist in an intranet environment; it gives you a lot of stuff for free.
Of course, it has very rough elbows, so to speak, so proceed with caution.
I wouldn't think of the applications as seperate but as modules of the overall portal.
I would recommend you look into MEF as this would seem to be a perfect fit.
http://blogs.msdn.com/hammett/archive/2009/04/23/mef-and-asp-net-mvc-sample.aspx

Do I need ASP.NET MVC?

I realize that ASP.NET MVC has all the hype. I have my doubts that I need it, but wanted to explain my potential project:
This is an internal LAN application. It is doing CRUD operations and a little reporting.
The user base is small (< 12 people) and there is not tons of data
There is not a huge number of screens (Maybe 20)
I don't care about URL rewriting
My view state is typically small (like a DealID or ClientID)
Even though I don't have a full mastering of Page Lifecycle, I do understand Postbacks and don't have a problem coding for it.
I believe in Layering and am familiar with the M-V-P pattern and other patterns.
I want to do some Unit testing, but heck 25-50% coverage is better then what most apps.
The app will have a little AJAX for search screens, but don't see it being overkill.
So what do you think? While using the "sexy" technology is cool, is it necessary?
No, it's not necessary. It sounds like you've already made up your mind. If the application isn't all that critical and you're more familiar with web forms, just do it the way you know how to. I think ASP.NET MVC is worth learning, but it isn't the right solution for every project. Go and try it out in your free time so that when this situation comes up again, you'll have more options available to you.
No you don't strictly need MVC but are you asking whether you should learn something new or use what you already know for an internal project? An internal project might be the perfect place to try out something new.
As was said, it's not necessary. However, if you're doing a basic CRUD application (and it sounds like you are), MVC would make that nice and easy.
You mention you're moving to project management. Do you think any of the projects or products you look into will be using MVC? If so then at least you'll have some familiarity by learning it with this small application. This means it is necessary, if you need it as a PM, but you do not require it just to build the app. It could run with anything you choose.
Incidentally, ASP.NET MVC is new, not MVC, not by any stretch of the imagination. I know you did not say it was, but you mention hype. I cannot help but think Java and other folks are saying, "We've been doing this for years and years."
You can use both.
Create a Visual Studio Web Application (not a website), and you'll be able to use both if needed.
You'll just need to add a reference to MVC and setup the routing.
Webforms and MVC
It's not necessary, no, but there's no reason why you can't use webforms or MVC.
If you feel comfortable working with webforms, then go down the webforms approach. If, however, you feel the need to broaden your knowledge of architectural patterns, then ASP.NET MVC is a pretty nice thing to use.
If unit testing is important to you, go with MVC. Everything else you mentioned, though, points to WebForms.

Should I build my next web app in ASP.NET MVC?

My team is considering building our next web app using the ASP.NET MVC framework. I am slightly hesitant, as are some others, because it is still only in beta. I really want to dive in because it seems to be a great way of providing clear separation of concerns and improving testability.
Should I take the plunge now, while MVC is still in beta, or hold off for a release candidate?
From some of the responses, I think I need to clarify my question a bit. My primary concern is whether to go with a product that's still in beta, not webforms vs. mvc. The concern is mainly because of the fear that we end up using some functionality in the beta version that gets changed / deprecated / not supported in the final release.
However, I do appreciate the perspective on webforms vs. mvc. It just doesn't get at the heart of my question.
It's a pretty simple decision tree, really.
Choose ASP.NET MVC if you...
Care deeply about URLs
Care deeply about your HTML
Want true separation of concerns
Want testability through and through
Want flexibility of view engines (ASPX, NVelocity, NHaml, etc)
Choose WebForms if you...
Enjoy the stateful abstraction of WebForms (ViewState)
Don't mind PostBack model
Prefer components that you can "drag & drop" on a page
For me, the answer will 99% be ASP.NET MVC, because I think it is a much better match for the web. I think the ajax story is much cleaner as well, and I have complete control over my HTML & URLs. On top of all of that, I can test-drive my website (controllers) quite easily.
Yes, I know you can achieve clean URLs in WebForms, and you can have clean(er) HTML through Control Adapters, and you can achieve a level of testability with the MVP pattern in WebForms, but these are all off-the-beaten path approaches. With ASP.NET MVC this stuff is core. That's just the way you do it.
And don't worry about the preview/beta status. The team has always maintained that you don't need a go-live license to deploy it (even though they now offer one). It's purely additive on the existing ASP.NET Runtime.
It's like automatic vs. manual transmission. Pick one that makes you happy and run with it.
I prefer ASP.NET MVC to WebForms, so I would choose that, but you need to work out as a team where your core skill set is and whether or not choosing MVC will:
Create a better product.
Get you to market quicker.
Don't just choose it because it's new. WebForms is still a great choice, and you can write code for WebForms that's both testable and has clear seperation of concerns.
So far Mvc looks good, however I m a castle advocate I have used monorail in many production sites and it got me into learning about IoC and AR
Cheack out castleproject.org
I'd recommend giving it a shot.
We just recently released an e-commerce platform with MVC running the front end, and while there are some gotchas that you may stumble upon (Say, resolving Url's with anonymous types is currently far slower than using a RouteValueDictionary, was a surprise to me), it certainly feels like it was a lot easier to build a manageable system in MVC compared to our older WebForms apps.
If you have the luxury of choosing, then you should definitely have a closer look. The bugs that have shown up while we worked on it have all been fixed fairly promptly, and most things work well now, and it's starting to feel pretty complete.
But in the end, it's always a risk to take on an early beta product. :)
Unless your app is super simple, it's likely that MVC will be released before you go to production. That hardly matters though. I have been building on MVC since Preview 2. Each new version has contained breaking changes; however, they have not been very hard to track down and fix. It's very unlikely that by 1.0 you could create a mountain of code that would be toppled over by some breaking changes. Simply budget a few person hours to apply each new version.
If you don't have to put your app in production soon, yes write it in MVC.
Here, we have a team working with MVC and planning to put it on prodution at jan/2009.
If it's not mission critical and you and your team have the time to learn it, why not?

ASP.NET MVC Performance

I found some wild remarks that ASP.NET MVC is 30x faster than ASP.NET WebForms. What real performance difference is there, has this been measured and what are the performance benefits.
This is to help me consider moving from ASP.NET WebForms to ASP.NET MVC.
We haven't performed the type of scalability and perf tests necessary to come up with any conclusions. I think ScottGu may have been discussing potential perf targets. As we move towards Beta and RTM, we will internally be doing more perf testing. However, I'm not sure what our policy is on publishing results of perf tests.
In any case, any such tests really need to consider real world applications...
I think this will be a hard question to definitively answer as so much will depend on A) how you implement the WebForms application, and B) how you implement the MVC application. In their "raw" forms, MVC is likely faster than WebForms, but years and years of tools and experience have produced a number of techniques for building fast WebForms applications. I'd be willing to bet that a senior ASP.NET developer could produce a WebForms application that rivals the speed of any MVC application- or at least achieve a negligible difference.
The real difference- as #tvanfosson suggested- is in testability and clean SoC. If improving performance is your chief concern, I don't think it's a great reason to jump ship on WebForms and start re-building in MVC. Not at least until you've tried the available techniques for optimizing WebForms.
It decreased one of my pages from 2MB payload, to 200k, just by eliminating the viewstate and making it bearable programatically to work with the submitted output.
The size alone, even though the processing was the same will create vast improvements in connections per second and speed of the requests.
I think that many of the people who think that WebForms are inherently slow or resource intensive are placing the blame in the wrong place. 9 times out of 10 when I am brought in to optimize a webforms app there are way too many places where the apps authors misunderstand the purpose of the viewstate. I'm not saying that the viewstate is perfect or anything, but it is WAY too easy to abuse it, and it is this abuse that is causing the bloated viewstate field.
This article was invalueable in helping me understand many of these abuses. https://weblogs.asp.net/infinitiesloop/truly-understanding-viewstate
In order to make a valid comparison between MVC and WebForms we need to be sure that both apps are using the architectures correctly.
My testing shows something between 2x and 7x more req/sec on MVC, but it depends how you build your webforms app. With just "hello world" text on it, without any server side control, mvc is around 30-50% faster.
For me the real "performance" improvement in MVC is the increase the testable surface of the application. With WebForms there was a lot of the application that was hard to test. With MVC the amount of code that becomes testable basically doubles. Basically all that isn't easily testable is the code that generates the layout. All of your business logic and data access logic -- including the logic that populates the actual data used in the view -- is now amenable to testing. While I expect it to be more performant as well -- the page life cycle is greatly simplified and more more amenable to web programming -- even if it were the same or a little slower it would be worth switching to from a quality perspective.
I think the problem here is that no matter how much faster ASP.Net MVC is than the old webforms, it won't make a difference, because most of the time taken is in the database. Most of the time, you web servers will be sitting at 0-10% CPU usage just waiting on your database server. Unless you get an extremely large number of hits on your website, and your database is extremely fast, you probably won't notice a big difference.
The only concrete numbers I can find which are from early ASP.NET MVC-development is on this forum-thread:
http://forums.asp.net/p/1231621/2224136.aspx
Rob Connery himself somewhat confirms statement that ScottGu has claimed that ASP.NET MVC can serve 8000 requests per second.
Maybe Jeff and his crew can give some kind of hint from their development of this site.
Contrary to the accepted opinion, optimized webforms usage completely kills MVC in terms of raw performance. Webforms has been hyper-optimized for the task of serving html far longer than MVC has.
Metrics are available on http://www.techempower.com/benchmarks/#section=data-r7&hw=i7&test=db
Every single comparison mvc is on the lower-middle/lower-upper rankings of the list, while optimized webforms usage places in the upper-middle/upper-lower rankings.
Anecdotal but very serious validation to these metrics, www.microsoft.com is served by webforms not MVC. Does anyone here believe that they wouldn't have chosen MVC if it was empirically faster?
There's really no way to answer this. MVC uses the Web Forms view engine by default itself, and can be configured to use any number of custom view engines, so if you want a performance comparison you'll have to be more specific.
I started out work in MVC about a year ago, I was inspired but not impressed.
I loath the view state and see it as the root of all evil in terms of ASP.NET. This is why I just don't use it and to be perfectly honest why would you?
I took basically the ASP.NET MVC Framework concept and built that in my own way. I changed a couple of things though. I built my controller wrapping code, or URL routing code around dynamic recompilation.
Now, I would go as far as to say that ASP.NET MVC applications will be faster based on how you use it. If you completely abandon WebForms you'll be faster becuase the ASP.NET life-cycle and object model is humongous.
When you're writing you're instantiating an army... no wait, a legion of objects that will participate in the rendering of your view. This is gonna be slower than if you where to express the minimal amount of behavior in the ASPX page itself. (I don't care about view engine abstraction because the support for ASPX pages in Visual Studio is decent, but I've completely dropped WebForms as a concept and basically any ASP.NET framework due to code bloat or not being able to change the things that wire my application).
I've found ways of relying on dynamic recompilation (System.Reflection.Emit) for emitting special purpose objects and code whenever needed. The executing of this code is faster than reflection but initially built through the reflection service. This has given my MVC flavored framework great performance but also very statically typed. I don't use strings and name/value pair collections. Instead my custom compiler services goes in a rewrites a form post to a controller action being passed an reference type. Behind the scene there is a lot of things going on but this code is fast, a lot faster than WebForms or the MVC Framework.
Also, I don't write URLs, I write lambda expressions that get translated into URLs that later tell which controller action to invoke. This isn't particularly fast but it beats having broken URLs. It's like if you had statically typed resources as well as statically typed objects. A statically typed web application? That is what I want!
I would encourage more people to try this out.
The projects created with visual studio. One is mvc4 template, another is WebForm (tranditional).
And when make load test with WCAT, this is the result,
MVC4 is quite slow than WebForms, any ideas?
MVC4
could get about 11 rps
rps is quite low both 2-cpu or 4-cpu server
WebForms (aspx)
could get above 2500 rps
the performance killer has been found that it's a bug of MVC Bata or RC.
And The performance would be improved once i remove Bundles things. Now the latest version fixed this.
Performance depends on what you are doing... Usually MVC is faster than asp.net mostly because Viewstate is absent and because MVC works more with Callback than Postback by default.
If you optimize your webform page you can have the same performance as MVC but it will be a lot of work.
Also, their is a lot of nugets for MVC (and also for Webform) to help you to improve website performance like combine and minify your css and javascripts, group your images and use them as a sprite, and so on.
Website's performance depend greatly of your architecture. A clean one with good separation of concern will bring you a more clean code and a better idea of how improve performance.
You can take a look at this template "Neos-SDI MVC Template" which will create for you a clean architecture with lots of performance improvements by default (check MvcTemplate website).
I did a small VSTS load test experiment with some basic code and found ASP.NET MVC response time to be twice faster as compared to ASP.NET Webforms. Above is the attached graph with the plot.
You can read this load test experiment in details from this CP article https://www.codeproject.com/Articles/864950/ASP-NET-MVC-vs-ASP-NET-WebForm-performance-compari
Test was conducted with the below specifications using VSTS and telerik load test software:-
User load 25 users.
Run duration of test was 10 minutes.
Machine config DELL 8 GB Ram, Core i3
Project was hosted in IIS 8.
Project was created using MVC 5.
Network LAN connection was assumed. So this test does not account for network lag for now.
Browser in the test selected Chrome and Internet explorer.
Multiple reading where taken during the test to average unknown events. 7 readings where taken and all readings are published in this article as reading 1 , 2 and so on.

Resources