ASP.NET Web API, MVC, ViewModels and Formatters

Original: Posted by Jimmy Bogard on April 10, 2012

There are probably a few more terms I can throw in there, but over the past few days, I’ve been struggling to bridge the gap from how I build applications in ASP.NET MVC and how I see folks building them in ASP.NET Web API (and other HTTP-centric frameworks).

These days, the de facto standard for building MVC applications looks something like this for GETs:


And for POSTs:


We’re using the same ViewModel for both GET and POST, where in one case the ViewModel is used in the View to build a form, and in the other case, the exact same model is used on the POST side to model bind from HTTP variables into something we can reason with.

Continue reading

Making ASP.NET Output Cache Work with Post-Back

Making ASP.NET Output Cache Work with Post-Back.

ASP.NET Output Cache & Post-Back

ASP.NET’s page caching and user control fragment caching prevents post-back from working because, during post-back, a cached version of the page may be displayed instead of the form submission being processed. However, all is not lost! I’ve found a simple solution to this using a HTTP module to bypass the output cache during post-back. This allows the initial page view to be cached to disk, but – and here’s the good bit – user interaction via post-back remains un-cached, so you get the benefits of post-back while losing none of the goodness of output caching!

Continue reading

Optimize ASP.NET Membership Stored Procedures for greater speed and scalability

Here is a good article from Omar AL Zabir. If you are also using ASP.NET Membership/Role/Profile providers, or at least checking if you can use it as i do, it has pretty good and practical results. Thanks Omar for this informative and beneficial article.

Last year at Pageflakes, when we were getting millions of hits per day, we were having query timeout due to lock timeout and Transaction Deadlock errors. These locks were produced from aspnet_Users and aspnet_Membership tables. Since both of these tables are very high read (almost every request causes a read on these tables) and high write (every anonymous visit creates a row on aspnet_Users), there were just way too many locks created on these tables per second. SQL Counters showed thousands of locks per second being created. Moreover, we had queries that would select thousands of rows from these tables frequently and thus produced more locks for longer period, forcing other queries to timeout and thus throw errors on the website.

If you have read my last blog post, you know why such locks happen. Basically every table when it grows up to hold millions of records and becomes popular goes through this trouble. It’s just a part of scalability problem that is common to database. But we rarely take prevention about it in our early design.

Continue reading

The difference between ASP.NET Web Site and ASP.NET Web Application

I have just read this at


The Web Site project is compiled on the fly. You end up with a lot more DLL files, which can be a pain. It also gives problems when you have pages or controls in one directory that need to reference pages and controls in another directory since the other directory may not be compiled into code yet. Another problem can be in publishing.

If VS isn’t told to re-use the same names constantly, it will come up with new names for the dll files generated by pages all the time. That can lead to having several close copies of dlls containing the same class name, which will generate plenty of errors. The Web Site project was introduced with VS 2005, but has turned out not to be extremely popular.

Web Application:

The Web Application Project was created as an add-in and now exists as part of SP 1 for VS 2005. The main differences are the Web Application Project was designed to work similar to the Web projects that shipped with and VS 2003. It will compile the application into a single dll at build time. In order to update the project it must be recompiled and the dll published for changes to occur.

Another nice feature of the Web Application project is it’s much easer to exclude files from the project view. In the Web Site project, each file that you exclude is renamed with an exclude keyword in the filename. In the Web Application Project, the project just keeps track of which files to include/exclude from the project view without renaming them, making things much tider.


This article also gives reasons on why to use one and not the other. Here is an excerpt of it:

  • You need to migrate large Visual Studio .NET 2003 applications to VS 2005? use the Web Application project.
  • You want to open and edit any directory as a Web project without creating a project file? use Web Site project.
  • You need to add pre-build and post-build steps during compilation? use Web Application project.
  • You need to build a Web application using multiple Web projects? use Web Application project.
  • You want to generate one assembly for each page? use Web Site project.
  • You prefer dynamic compilation and working on pages without building entire site on each page view? use Web Site project.
  • You prefer single-page code model to code-behind model? use Web Site project.

10 Insanely Useful Django Tips

One of the reasons i add posts in this blog is to open it in the future and read my posts. I can say this is a kind of bookmarking for me. This post will be a bookmark to revisit in the future.

Here is the next article i have read in and think really useful. I read many things about Django and it seems really cool. Although I couldn’t create a full application with it yet, i am sure it will be really nice to use Django.

This article is from Glen Stansberry who is a web developer and blogger. You can read more tips on web development at his blog Web Jackalope or follow him on Twitter.

There are quite a few great little tricks and tips one could use on their Django projects that would speed up development and save many headaches in the long run. From basic to obscure, these tips can help any skill-level of programmer become more adept with Django and all it’s glory.

Continue reading

The PHP Benchmark

I found when i was stumbling. It is a simple but good site that lists some performance issues with basic php functions and usage of them. was constructed as a way to open people’s eyes to the fact that not every PHP code snippet will run at the same speed. You may be surprised at the results that this page generates, but that is ok. This page was also created so that you would be able to find discovery in these statistics and then maybe re-run these tests in your own server environment to play around with this idea yourself, by using the code examples (these code examples are automatically generated and as the code in my .php files change, so do they).

You should take a look to see basic differences of using those functions and what you are doing right / wrong.

5 useful url rewriting examples using .htaccess

If you are looking for the examples of URL rewriting
then this post might be useful for you.

Now let’s look at the examples:

1)Rewriting product.php?id=12 to product-12.html

It is a simple redirection in which .php extension
is hidden from the browser’s address bar and dynamic url (containing
“?” character) is converted into a static URL.

RewriteEngine on

RewriteRule ^product-([0-9]+)\.html$ product.php?id=$1

Continue reading