Use ASP.NET MVC for html brochure websites? - asp.net-mvc

I have a project that will basically be a large brochure html website. Although some content could possibly be database driven in the future. I use ASP.NET MVC for any database driven websites usually, but not sure whether to use it for brochure html websites.

You'd probably want to use Master Pages even if the content is static. Might as well use MVC to keep headers and footers consistent across the site. (Same goes for any language, really.)

You host only plain old html files in it for now. If the need arises for database-driven content, ASP.NET MVC's routing options make it easy to switch to a dynamic site without breaking the links.
We used the same approach for setting up a dummy website for SEO purposes until the real app was developed and the switch to dynamic content was effortless.

The good thing about ASP.NET MVC (as apposed to Webforms? I assume you're asking) is that you can just use basic html and have a designer design up brochure required. If this needs to be more "dynamic" at some stage with forms or CMS etc, using the existing plain html will be easier.
Also if you're using MVC already its a no-brainer...

Danny,
it's possibly also a choice over whether your project sponsor is wanting to pay for windows hosting or whether they go down the linux route. if you know for sure that the site would NEVER be required to take data from a database then you could actually create an app in mvc (your developer app) and then have that app generate the 'flat file' site out to html files. that way, you could store the elements that make up the content in your developer database and regenerate the entire site when required. This approach would reap dividends - for example you decided to add some jquery across the site, then this would do it all in a single hit.
this way of generating flat sites would mean that you could in theory have an engine that you used for multiple clients, changing only the css and content as required.
just my tuppence worth...
jim

Related

VS2013 - How to create a skeleton template for MVC5 IoC project

As a way of raising the standards of our codebase I would like all new web projects (where possible) to use MVC5 with Inversion of Control. I'd like to have a service, domain and repository layers. Plus Unit Tests to get them started.
Obviously this is a lot of code to do up front for every project, and I want to avoid "just copy ProjectXYZ and strip out what you don't need" as this has been fraught with human errors in the past.
How do I take my very basic skeleton solution and turn it into a template for my colleagues to do File -> New Project etc ?
They could just copy the .sln I create, but it seems like there might be a more professional way to do it.
Perhaps there is already one out there we can use?
I am the developer of ASP.NET MVC Boilerplate (I found this question by checking my GitHub traffic and seeing #floatas's link, so thank you #floatas).
The default MVC project template is too basic and gives you very little out of the box. The idea behind ASP.NET MVC Boilerplate is to write all the boilerplate code for you, so you don't have to.
Now it does not contain unit tests, repositories etc. but it does include a lot of other things that every website requires.
Secure By Default
The default MVC template is not as secure as it could be. There are various settings (Mostly in the web.config file) which are insecure by default. For example, it leaks information about which version of IIS you are using and allows external scripts to access cookies by default!
ASP.NET MVC Boilerplate makes everything secure by default but goes further and uses various HTTP headers which are sent to the browser to restrict things further.
It also makes use of the new Content Security Policy (CSP) HTTP Header using the NWebSec NuGet packages. CSP revolutionizes web security and I highly recommend reading the above link.
Setting up SSL/TLS, so that your site runs over HTTPS is made easy with easy step by step instructions and links.
Fast By Default
The default MVC template does a pretty poor job in the performance department. Probably because they don't make any assumptions about which web server you are using. Most of the world and dog that are writing ASP.NET MVC sites use IIS and there are settings in the web.config file under the system.webServer section which can make a big difference when it comes to performance.
ASP.NET MVC Boilerplate makes no such assumptions. It turns on GZip compression for static and dynamic files being sent to the browsers making them smaller and quicker to download. It also uses Content Delivery Networks (CDN) by default to make common scripts like jQuery quicker to download (You can turn this off of course but the point is ASP.NET MVC Boilerplate is fast by default).
That's not all! There are a bunch of other tweaks and examples of practices which can help improve the performance of the site. ASP.NET MVC Boilerplate achieves a score of 96/100 on YSlow (Its not possible to get the full 100 as some of it's criteria contradict each other and site scripts need to be moved to a CDN which you need to do yourself).
Search Engine Optimization (SEO)
The default ASP.NET MVC template takes no consideration of Search Engine Optimization at all. ASP.NET MVC Boilerplate adds a dynamically generated robots.txt file to tell search engines which pages they can index. It also adds a dynamically generated sitemap.xml file where you can help search engines even further by giving them links to all your pages.
ASP.NET MVC has some very useful settings for appending trailing slashes to URL's and making all URL's lower case. Unfortunately, both of these are turned off by default, which is terrible for SEO. This project turns them on by default.
It also includes an MVC filter which helps to redirect non-canonical URL's (URL's without a trailing slash or mixed case characters which are considered different URL's by search engines) to their canonical equivalent.
Accessibility
4% of the world population is estimated to be visually impaired, while 0.55% are blind. Get more statistics here. ASP.NET MVC Boilerplate ensures that your site is accessible by adding aria attributes to your HTML mark-up and special shortcuts for people using screen readers.
Browser Compatibility
Websites need to reach as many people as possible and look good on a range of different devices. ASP.NET MVC Boilerplate supports browsers as old as IE8 (IE8 still has around 4% market share and is mostly used by corporations too lazy to port their old websites to newer browsers).
ASP.NET MVC Boilerplate also supports devices other than desktop browsers as much as possible. It has default icons and splash screens for Windows 8, Android, Apple Devices and a few other device specific settings included by default.
Resilience and Error Handling
At some point your site is probably going to throw an exception and you will need to handle and log that exception to be able to understand and fix it. ASP.NET MVC Boilerplate includes Elmah, the popular error logging addin by default. It's all preconfigured and ready to use.
ASP.NET MVC Boilerplate uses popular Content Delivery Networks (CDN) from Google and Microsoft but what happens in the unlikely event that these go down? Well, ASP.NET MVC Boilerplate provides backups for these.
Not only that but standard error pages such as 500 Internal Server Error, 404 Not Found and many others are built in to the template. ASP.NET MVC Boilerplate even includes IIS configuration to protect you from Denial-of-Service (DoS) attacks.
Easier Debugging and Performance Testing Tools
ASP.NET MVC Boilerplate makes use of Glimpse (As advertised by Scott Hansleman here). It's a great tool to use as you are developing, to find performance problems and bugs. Of course, Glimpse is all preconfigured, so you don't need to lift a finger to install it.
Patterns and Practices
Doing things right does sometimes take a little extra time. Using the Inversion of Control (IOC) pattern for example should be a default. ASP.NET MVC Boilerplate uses the Autofac IOC container by default. Some people get a bit tribal when talking about IOC containers but to be honest, they all work great. Autofac was picked because it has lots of helpers for ASP.NET MVC and Microsoft even uses it for Azure Mobile Services.
ASP.NET MVC Boilerplate also makes use of the popular Less files for making life easier with CSS. For an example, it can make overriding colours and fonts in the default Bootstrap CSS a cinch.
ASP.NET MVC is a complicated beast. You can end up with lots of magic strings which can be a nightmare when renaming something. There are many ways of eliminating these magic strings but most trade maintainability for slower performance. ASP.NET MVC Boilerplate makes extensive use of constants which are a trade-off between maintainability and performance, giving you the best of both worlds.
Search
There is a lot more to implementing search in your application than it sounds. ASP.NET MVC Boilerplate includes a search feature by default but leaves it open for you to choose how you want to implement it. It also implements Open Search XML right out of the box. Read Scott Hanselman talk about this feature here.
Social
Open Graph meta tags and Twitter Card meta tags are included by default. Not only that but ASP.NET MVC Boilerplate includes fully documented HTML helpers that allow you to easily generate Open Graph object or Twitter Card met tags easily and correctly.
There is RehanSaeed/ASP.NET-MVC-Boilerplate, aspnetboilerplate.com and probably many more tools to generate starting template. They are open source and can be installed as a plugin, so you can change the way you like and give to your team.
If you still really want to create your own, you can follow these steps. I can't include them all here because they are quite long.

Special kind of Server Side Include of Asp.net MVC

i have to create a new asp.net mvc page that integrates content provided by a cms on the server side static. my mvc page provides a masterpage with the navigation and certain links should point to pages of the cms (which is installed on the same server). it should be something like a "server side iframe".
my idea is to create a controller which loads the page of the cms using a webrequest, extracts the body part of the page and passes the extracted data to the view. the view simply outputs the passed html. i also plan to add some logic to pass post requests to the cms (for news letter subscriptions, contact forms, ...)
now my question is: is it possible to implement this solution? or is there a better way to do this on the server side?
Could you use Application Request Routing to just hand off requests to your CMS, or do you need to include the externally provided content within an existing masterpage?
If you need to use the masterpage I would stick to the solution you suggest, although I might investigate the most robust and efficient option for querying the content from the CMS and perhaps if caching would be a good option.
It is undoubtedly possible, but keeping track of users, authentication, cookies etc. seems like a really tedious job. Also, embedding css classes, hard-coded styling etc. from the CMS in your MVC site could give you a severe headache.
If the CMS isn't home-brewed it probably has an API. In that case I would much prefer to use the API to get at the data I needed and then render that data using pure MVC. This will give you a much cleaner and more stable integration with the CMS.

Flatpages equivalent for ASP.Net MVC

Django has the Flatpages app, which lets site admins change content on specific pages without changing code. Flatpage content i stored in the database, sort of like in a CMS. Flatpages are typically used for about-pages and such.
Are there any good equivalents for ASP.Net MVC? I.e., a convenient way to manage page-content persisted to a database.
No.
Django seems closer to a CMS then "ASP.NET MVC" which is both a framework and just a general design pattern.
Have a look at http://http://cmsmvc.codeplex.com, it allows you to create pages, and manage content on the page.
The solution is still in early stages, but it could help you out.

form tag - is it required on ajax sites?

i recently was working on an ASP.NET MVC site that basically serves static html and uses ajax gets to return data to the page when inputs are changed. there is actually no posting or getting from an html input tag on the pages at all. (it is a specific style of site that is not used by the general public, so having compatibility problems for people without javascript is not an issue)
after designing the site, i realised that i hadn't even included any form tags. as the site does not use any direct posts or gets, and apart from it being just good html design, i wondered, in my particular situation, if there was any point to having any form tags on the page?
As ASP.NET MVC tries to differ from Web Forms, to introduce a new approach in designing web applications. They do not require forms. In fact i think it's better not to be used for navigation, submitting data, etc. Otherwise, there is no use of the MVC pattern if you still do it "the good old ASP.NET" way.
Of course ... I'm sure there are good reason forms to be used in proper places, but not as a general concept in your design.
You can read here: http://msdn.microsoft.com/en-us/magazine/cc337884.aspx how MVC was introduced in the beginning. "ASP.NET MVC - Building Web Apps without Web Forms" by Chris Tavares
Retaining a form is useful if you need your application to degrade gracefully if JavaScript is disabled or the likes. Also, jQuery and Prototype have nice Ajax helpers for serializing inputs using a form, which is really nice when you have multiple sets of data that could be submitted to different ajax endpoints from one page.
So I guess the answer to my question is no.

ASP.NET MVC+ multilingual page

I'm developing a website using ASP.NET MVC. The website should handle multiple languages.
I would like to ask what are the best practices of handling multiple languagues - both for "static" texts and taken from DB. I read some threads about this on stackoverflow but i'm not sure how can I implement in when data from DB are received. I also read this article
Well, if you need to localize your web application then you can't really use any "static" text. The article link you included talks about using resource files. While this does work in ASP.Net MVC it means that everything in your view pages will have to be an ASP.Net Literal control and you have to push ALL of your textual content into the .RES file and not put any of it in your view pages.
If you have a lot of users from different cultures then using the .RES files will be the way to go. If you have the majority of your users all in one language and just a small percentage in a different language then you may be able to take advantage of Microsoft’s translation engine. You just embed some JavaScript in your page and Microsoft will translate the page’s text for you.

Resources