Pages

Monday, May 19, 2014

Things to do in a fresh ASP.NET MVC Project

Do remove the custom ASP.NET HTTP response headers

There's no need to send

X-Powered-By: ASP.NET
X-AspNet-Version: 2.0.50727
X-AspNetMvc-Version: 2.0

To your client's browsers all the time.  Add this to in your application's startup to stop doing it.

MvcHandler.DisableMvcResponseHeader = true;

Do use code analysis (fxcop) on build

Use project -> properties -> code analysis to configure it.  It's a lot less painful if you do it from the beginning.

Do decide what to do with your XML and JSON formatters

You can do this and just remove XML as a supported response type.


    GlobalConfiguration.Configuration.Formatters.XmlFormatter.SupportedMediaTypes.Clear();

BUT you may want to support JSON API calls in the future.  If you don't, I suggest just removing the formatter.

Do install the Web Essentials Plugin

http://visualstudiogallery.msdn.microsoft.com/56633663-6799-41d7-9df7-0f2a504ca361

This plugin contains many experimental features that eventually make it into ASP.NET, but is very stable.  

Do create a Visual Studio schema comparison for your various database environments.

This is the simplest way for a developer without 3rd party products to move schema changes between Dev/QA/Staging/Prod

Do create XML document transform files for your various environment deployments.

In production, be sure to use to prevent yourself from accidentally leaking stacktraces and to ensure you're compiling for release

<configuration>
  <system.web>
    <deployment retail="true"/>
  </system.web>
</configuration>

Do create an appoffline.htm page

By default, your web server will server this file for all requests if it exists in the root of your web application.  Be sure to embed any CSS/JS you use, users won't be able to request your application's CSS/JS files when this file exists!

Consider installing SignalR for real time application features.

It's important to consider your installation of Signalr because SignalR 2.0 now requires .NET 4.5.  If you're planning on making an application or set of libraries that work under 4.0

Bonus : General Visual Studio Tips


Do learn the hotkeys
  • ctrl + , 
  • ctrl + q
  • ctrl + k + x
The first two you will find yourself using all the time after you learn them.

Ctrl + , will intelligently search your code in Visual Studio 2013.  It's still useful in 2012 and less, but the 2013 version will knock your socks off.



ctrl + q is the closest you'll get to a command line IDE.  You can search just about anything outside your project in visual studio by hitting control + q.  A cool bonus is that the input is buffered; for example, if you quickly type ctrl + q + type 'sql' + enter it will still bring you to the  before the results are rendered, it will catch your input and immediately bring up your result in the IDE.  


The last, try yourself!  It's the homework for the reader

Note : some of these recommendations are sourced from http://stackoverflow.com/questions/54929/hidden-features-of-asp-net 


1 comment:

  1. This comment has been removed by a blog administrator.

    ReplyDelete