Quantcast
Channel: Scalability Blog » ASP.NET
Viewing all articles
Browse latest Browse all 10

Tips and Tricks on how to improve MVC Application Performance

$
0
0

In this post we will cover a few tips and tricks to improve ASP.NET MVC Application Performance.

Run in Release mode

Make sure your production application always runs in release mode in the web.config


or change this in the machine.config on the production servers


    
          
    

Only use the View Engines that you require

protected void Application_Start() 
{ 
	ViewEngines.Engines.Clear(); 
	ViewEngines.Engines.Add(new RazorViewEngine()); 
}

Use the CachedDataAnnotationsModelMetadataProvider

ModelMetadataProviders.Current = new CachedDataAnnotationsModelMetadataProvider();

Avoid passing null models to views

Because a NullReferenceException will be thrown when the expression gets evaluated, which .NET then has to handle gracefully.

// BAD
public ActionResult Profile() 
{ 
	return View(); 
}
// GOOD
public ActionResult Profile() 
{ 
	return View(new Profile()); 
}

Use OutputCacheAttribute when appropriate

For content that does not change often, use the OutputCacheAttribute to save unnecessary and action executions.

[OutputCache(VaryByParam = "none", Duration = 3600)]
public ActionResult Categories() 
{ 
	return View(new Categories()); 
}

Use HTTP Compression

 


Remove unused HTTP Modules

If you run into any problems after removing them, try adding them back in.


      
      
      
      

Flush your HTML as soon as it is generated


Turn off Tracing


     
          
     

Remove HTTP Headers

This is more of a security thing


    


 
  
 

Uninstall the URL Rewrite module if not required

This saves CPU cycles used to check the server variable for each request.

Go to "Add or Remove Programs" and find "Microsoft URL Rewrite Module" and select uninstall. 

Don’t write rubbish code

Just don’t.


Viewing all articles
Browse latest Browse all 10

Latest Images

Trending Articles





Latest Images