MVC configuration – ‘path’ attribute inside ‘location’ section

This is post about specifying path attribute of location section in Web.config file. If you are not familiar with this section, go here

Examples in above article concern about ASP.NET where specifying path like ‘Page1.aspx’ is enough.
When I started mapping this knowledge to ASP.NET MVC, first time I failed.
As a test environment I used default ASP.NET MVC project (not empty) to have ready to work profject structure. What I wanted is to override key “test1” for my Index view. Index view was rendered through the Index action of Home controller. I started with following:

  <location allowOverride="false" path="Index">
      <add key="test1" value="test4" />

Unfortunately it did not work.

I found out that in MVCC, where routing module does all work, we need to specify full path to the action, not just the ‘action’ name. Like following (working code):

  <location allowOverride="false" path="Home/Index">

Note here: specifying the path started from ~/ (root in MVC) is not allowed here and will not be resolved to the proper path!

This entry was posted in ASP.NET. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s