Alexander Beletsky's development blog

My profession is engineering

Inside ASP.NET MVC: Setting up project for hacking

As we already got debug assembly and pdb file, it it time to create a test project that would be a sandbox for all experiments. This would be classic MVC application, but we going to substitute release version of MVC framework with our locally built version, which allows us easily debug it.

Create new project

Let’s create new project. It would be MVC 3 Application:

new project

On a second step just select “Empty” in “Select template” dialog. “Razor” would be for view engine.

Correct system.web assemblies section

Go to web.config of a new project and comment out System.Web.Mvc and System.Web.WebPages assemblies. By doing that we saying: “those 2 assemblies are no longer a part of compilation of our application”.

web.config

UPDATE: If you do just that, later you will get an exception from Razor assemblies, about wrong type cast. To avoid that, it is even better to remove all assemblies in this section, plus Find/Replace PublicKeyToken=31bf3856ad364e35 to PublicKeyToken=null. That would do not make application to search GAC for missing assemblies and load locally built ones.

Correct application references

Now, remove existing references for System.Web.Mvc and System.Web.WebPages and put locally built ones instead. Right click on references project section and browse to the Debug folder of mvc3-rtm build directory. Try to build application now, it should be build without any issues.

setup

Home controller

Further steps are pretty simple, just add a test controller - HomeController with Index action. Add just a simple view for that.

controller

Check it out!

Place a breakpoint into action method and press F5 to start debugger. Now you we’ve got a full stack trace that allows to see every aspect of MVC world.

stack

Conclusion

The setup is easy and allows to jump in very quick. If you got any issues with that, please let me know.

What is next?

Next I will hack the entry point of MVC application called MvcHandler and understand how it works.

Please stay tuned.