Advice on using ASP.net WebForms or MVC

2019-01-28 04:16发布

问题:

I have a public facing hobby site that gets about 3000 unique visitors a day, written in classic ASP that is in bad need of a revamp and redesign. I've faced the realization that an upgrade to ASP.net is the best way to go to implement features that are just too hard in ASP for the hobbyist (consuming RSS feeds, authentication and user profiles) but which I'm keen to get stuck into once I get past the redesign/upgrade.

But, I have been paralysed with uncertainty about which way to go: Web Forms or MVC - plus the fact that there always seems to be some new release about to launch that seems like it would be worth holding out for to improve the learning curve. So I spend hours reading about WebForms then read something that tells me I might be better off thinking about MVC, then read about MVC and wonder whether it actually suits what I'm trying to do.

None of the tutorials and starter sites really talk about what works well for sites that are traditional old static information sites (not catalogues or user-content-driven).

My site is about 75% static information pages that rarely change. However, the ASP scripting is essential in the user interface on all those pages - dynamically or randomly picking design elements (like a header photo) or providing a particular sidebar box based on the day of the year or at random.

The kind of scripting I have is things like a script to randomly pick and display one of 30 header images for the page, a script to display text and links based on what day of the year it is, a script that allows me to declare a particular search keyword as being relevant to the content for a particular page and having that pre-loaded as the text in the search input box when the page loads.

For most of the rest of the pages, they are about displaying data. Some of them are small recordsets (almanac type information about what is significant about this particular day of the year) and I save it and pull it from an Array variable in the page itself. Others pull information from an Access database that changes rarely enough that I've never bothered implementing CUD functionality live on the site (and the necessary roles and authentication to secure it), but just update the database offline and upload it to send the changes live.

With ASP.net, I would be fine moving to SQL Server and building live administration pages. I don't need to stick with Access.

But, I'm more used to writing raw HTML and CSS and I'm finding WebForms (especially Viewstate and events/postbacks) a challenge to get my head around conceptually. Even though it seems to fit more with the static page in a file system with some server-side code that I'm used to.

On the other hand, MVC seems to be well suited to lovingly hand-coded design, but where everything gets pulled from a database.

What would you recommend? Should I pull all the static pages into a database and serve them through an "article" view in MVC?

I'm not a professional developer - so it's not about what will look best on my resume. I'm just looking for what will (a) have the least learning curve for someone coming from VBScript inline expressions in classic ASP and (b) what best suits what my site does and (c) lets me have some control over the mark-up and CSS.

回答1:

Definitely go MVC, especially if you're more comfortable as an HTML/CSS guy. Postbacks offer no advantage for a site that is largely static, and it will take months for you to get your head around the page lifecycle (I have yet to meet a developer who was a master of the lifecycle after 6 months of coding in it.)

Converting an ASP classic site to MVC will basically involve moving your HTML and ASP tags into Views, and replicating your existing URL's using the routing mechanisms. You'll need to upgrade your scripts to use some more modern functionality, but that should be fairly straightforward I would imagine.

I do disagree with the idea that in MVC everything is pulled from the database - that's a bit irrelevant to the architecture. I've coded 100% static sites in MVC frameworks and loved it :)

My rule of thumb is trending towards this: "MVC for websites, WebForms for enterprise web applications - maybe."



回答2:

MVC is well suited to what you're doing.

It's perfectly okay to have views which are static, if need be. Just take a look at what's generated by MVC's File->New Project template, for example.

Considering that you're already accustomed to writing HTML/CSS and both frameworks will present a learning curve, I'd definitely recommend MVC. I think you'll find MVC fits requirements A and C much better than WebForms too (and both satisfy B).



回答3:

Considering your experience I'll suggest you to use ASP.NET MVC. Since you're familiar with HTML & CSS you'll have to get used to the MVC pattern which is less than a week work. Also MVC is better and faster for just showing a data and it supports output caching so you can cache static pages and achieve awesome speed. Also it's not a problem to use a mix-up between the two - you can still have WebForms pages and use the controls where you need them.



回答4:

From my experience of passing from ASP to ASP.NET and ASP.NET MVC, it is easier to pass from ASP to ASP.NET MVC. However, the curve of learning is not so easy Please read and follow http://nerddinnerbook.s3.amazonaws.com/Intro.htm and , after you have read, see what's new in version 2 , for example :

weblogs.asp.net/scottgu/archive/2010/01/10/asp-net-mvc-2-strongly-typed-html-helpers.aspx

It will become a RAD for experienced developers!



回答5:

Use what is most productive, if you are familiar with webforms and like the event-driven model you can always look into MVP ( Model-View-Presenter ).

ASP.NET MVC is really great and for me, it increases productivity.



回答6:

First of all you really need to make sure that a rewrite is worth the effort. In my experience rewrites take much more work than expected and have a long payback time. That doesn't mean they shouldn't be done, it does mean there have to be a really good reasons to start one. The features you mention can easily be implemented in classic ASP in just a fraction of the time. A legacy application are battle scared by tweaks, bugfixes and hidden features. A rewrite generally means losing those years of experience. It all depends on the current features/ new features ratio.

Secondly, if you are going to rewrite, you might also want to checkout technologies besides asp.net. The site you describe seems to be very content orientated which might better fit django than asp.net mvc. Good luck with your site.



回答7:

I would also recommend you to use ASP.NET MVC as you are pretty much familiar with HTML/CSS. Also with the features like Routing you can organize the structure of the website in a more better way. Also your website becomes much more predictive for visitors because of the URL's.

Example :

www.domain.com/hobbies/photography