MVC On II6 Without the ".mvc" Extension

Last post 01-25-2008 10:23 PM by jamesgeurts. 11 replies.

Sort Posts:

  • MVC On II6 Without the ".mvc" Extension

    01-07-2008, 5:22 PM
    • Participant
      1,593 point Participant
    • mxmissile
    • Member since 06-19-2002, 10:42 AM
    • Ewtahh
    • Posts 362

    Can someone write a quick walk through to enable this? I know all requests including images, css files etc. will get handled by the Asp.Net engine, but this is for an internal non public facing project.  Performance is the least of my concern right now.

    http://www.heliosfx.com
  • Re: MVC On II6 Without the ".mvc" Extension

    01-07-2008, 7:23 PM
    • Participant
      983 point Participant
    • ChadThiele
    • Member since 04-27-2003, 2:43 AM
    • Japan
    • Posts 274

    Hi, it's called wildcard mapping and this post on msdn will help you out (I hope). Here's an excerpt from the article:

    To add a wildcard application mapping to a Web server or Web site

    1. In IIS Manager, expand the local computer, expand the Web Sites folder, right-click the Web site or virtual directory that you want, and then click Properties.

    2. Click the appropriate tab: Home Directory, Virtual Directory, or Directory.

    3. In the Application settings area, click Configuration, and then click the Mappings tab.

    4. To install a wildcard application map, do the following:
        On the Mappings tab, click Insert.
        Type the path to the DLL in the Executable text box or click Browse to navigate to it, select the Application Engine check box if the DLL is a script engine, and then click OK.

    ... 

    I had the same issue in the past when I was using UrlRewriter.net to handle url rewriting for a past project. Feels like I'm hacking something though, I don't really like it. IIS7 needs to be released soon so we don't need to do this. /hint hint. :D

    Did I answer your question(s)? Phweew...
  • Re: MVC On II6 Without the ".mvc" Extension

    01-07-2008, 8:25 PM
    • Participant
      983 point Participant
    • ChadThiele
    • Member since 04-27-2003, 2:43 AM
    • Japan
    • Posts 274

     Just a quick follow up, there some more discussion about IIS6 and wildcard mappings in this thread here.

    Did I answer your question(s)? Phweew...
  • Re: MVC On II6 Without the ".mvc" Extension

    01-07-2008, 11:56 PM
    • Member
      10 point Member
    • cubanx
    • Member since 10-25-2005, 1:39 PM
    • Posts 6

    mxmissile:

    Can someone write a quick walk through to enable this? I know all requests including images, css files etc. will get handled by the Asp.Net engine, but this is for an internal non public facing project.  Performance is the least of my concern right now.

     

     

    I've done this using the re-writer found here: http://cheeso.members.winisp.net/IIRF.aspx

     I'm too sleepy right now to do a full walk through, but the two tricks are

    1) Get the regex right that rewrites the url (I'm not at work right now, so I don't have it, but when I get to work tomorrow I'll post it) from www.mysite.com/Item/Edit/1 to www.mysite.com/Item.mvc/Edit/1

    2) Make sure you have both of these routes defined in your RouteCollection.  Make sure you have "[controller]/[action]/[id]" and "[controller].mvc/[action]/[id]" in that order.

     
    The reason for the second point up there is as follows:

    When you get the regex right to rewrite an incoming URL like "www.mysite.com/Item/Edit/1" it will rewrite it to "www.mysite.com/Item.mvc/Edit/1" 

    The second of the two routes up there will catch this and route it to your ItemController. 

    The reason for the second route is for outbound URL's.  So when you use something like Html.ActionLink<ItemController>(s => s.Edit(1), "MyLink") it will output the pretty URL of "www.mysite.com/Item/Edit/1"

     If this doesn't make a lot of sense (and it might not when I re-read it tomorrow morning Smile ) let me know and I'll post a step by step walk through from our internal wiki.

     We've got this all working internally with pretty URL's and all.  There is probably a better way, but right now for us, "good enough is ally of the best" Smile
     

  • Re: MVC On II6 Without the ".mvc" Extension

    01-18-2008, 8:36 AM
    • Member
      10 point Member
    • cubanx
    • Member since 10-25-2005, 1:39 PM
    • Posts 6

     Sorry this took so long to get out to you, but here is a walk through of getting this working:  (note, please don't be offended by the bolding, it's for internal devs who don't always read docs well Smile

    1. Make sure the .Net 3.5 Framework is installed.
    2. Find IsapiRewrite4.dll and IsapiRewrite4.ini at http://cheeso.members.winisp.net/IIRF.aspx
    3. Copy the IsapiRewrite4.dll and IsapiRewrite4.ini file to a directory of your choosing on the target web server. We've been using %WINDIR%\system32\inetsrv\System32\inetsrv MAKE SURE YOU PUT BOTH FILES IN THE SAME DIRECTORY!!!
    4. Click the Configuration button under the Virtual Directory/Website tab and add a mapping for .mvc mapping to .Net 2.0 framework. The extension is .mvc, use Limit to: GET, POST, HEAD, and make sure that "Verify that file exists" is UNCHECKED
    5. Install the IIRF isapi filter at the "Web Site" level using the information on where you installed it from above.
    6. Restart the World Wide Web Publishing service

    Here's our IsapiRewrite.ini file:

    1    RewriteLogLevel 3
    2 RewriteLog c:\logs\IIRF\rewrite
    3
    4 #This will rewrite one level deep if you are on localhost. In other words
    5 #if your url is http://localhost/MyDevEnvironment/[controller]/[action]/[id] it will
    6 #be able to rewrite it to http://localhost/MyDevEnvironment/[controller].mvc/[action]/[id]
    7 RewriteCond %{HTTP_HOST} ^.*localhost.*$
    8 RewriteRule (?!.*\..*)^/([^/.]+)/([^/.]+)(.*)$ /$1/$2.mvc$3 [L]
    9
    10 #This will rewrite root level if you are NOT on localhost. In other words
    11 #if your url is http://www.HeyThisIsACoolMVCSite.com/[controller]/[action]/[id] it will
    12 #be able to rewrite it to http://www.HeyThisIsACoolMVCSite.org/[controller].mvc/[action]/[id]
    13 RewriteCond %{HTTP_HOST} ^(?!.*localhost.*)$
    14 RewriteRule (?!.*\..*)^/([^/.]+)(.*)$ /$1.mvc$2 [L]
     Let me know if you need any help or have any more questions... 

     

     

    Filed under: ,
  • Re: MVC On II6 Without the ".mvc" Extension

    01-22-2008, 5:40 AM
    • Member
      28 point Member
    • byron.walker
    • Member since 01-11-2008, 1:55 AM
    • Posts 14

     You do not need this degree of complication.

     Just add the wildcard mapping as suggested in the initial replies.
     

  • Re: MVC On II6 Without the ".mvc" Extension

    01-22-2008, 6:35 AM
    • Contributor
      7,054 point Contributor
    • rjcox
    • Member since 12-19-2007, 2:14 PM
    • Basingstoke, UK
    • Posts 1,444

    byron.walker:

     You do not need this degree of complication.

     Just add the wildcard mapping as suggested in the initial replies.
     

     

    ... and then add your own handlers for all static types (.css, .jpg, ...), or use multiple v-dirs with different configuration.

    The point of using a URL rewriter is allow everything else (not request for MVC) to be left alone. 

    Richard
  • Re: MVC On II6 Without the ".mvc" Extension

    01-22-2008, 8:10 AM
    • Member
      10 point Member
    • cubanx
    • Member since 10-25-2005, 1:39 PM
    • Posts 6

    byron.walker:

     You do not need this degree of complication.

     Just add the wildcard mapping as suggested in the initial replies.
     

     

     Doing this is bad for performance since all requests get routed through the asp.net ISAPI handler.  I can't find the article that I read, but it stated up to a 30% performance improvement.  If you're just playing with a MVC, on a dev box or something internal or with low traffic, I think you can get away with this.

     Note in the link that is shown above: http://forums.asp.net/t/1192267.aspx Phil Haack commented this is not supported and not a good idea.

     Rob Conrey also suggests using IIRF in that same thread.

    I typed up the instructions since I hadn't found a step by step guide anywhere to setting this up so I thought I'd write one up.  It can probably be cleaned up (as most of my posts can be Smile ) but I just wanted to get it out there since I promised it to the OP.

     

  • Re: MVC On II6 Without the ".mvc" Extension

    01-25-2008, 7:06 AM
    • Member
      28 point Member
    • byron.walker
    • Member since 01-11-2008, 1:55 AM
    • Posts 14

     I make the same reply about performance as I always do.

     

    Show me a profile with a SIGNIFICANT difference in page load times AND that effect the usability of the site and Ill consider a more complex solution to better handle the routing. Otherwise, I like my urls without '.mvc' and so do my customers.

     

    Developer cycles are vastly more expensive than CPU cycles. 

  • Re: MVC On II6 Without the ".mvc" Extension

    01-25-2008, 10:36 AM
    • Participant
      1,593 point Participant
    • mxmissile
    • Member since 06-19-2002, 10:42 AM
    • Ewtahh
    • Posts 362

    byron.walker:

    Otherwise, I like my urls without '.mvc' and so do my customers.

     

    And (the main reason behind the OP) it makes a seamless transition to IIS7.

     

    http://www.heliosfx.com
  • Re: MVC On II6 Without the ".mvc" Extension

    01-25-2008, 8:53 PM
    • Member
      10 point Member
    • cubanx
    • Member since 10-25-2005, 1:39 PM
    • Posts 6

    byron.walker:

     I make the same reply about performance as I always do.

     

    Show me a profile with a SIGNIFICANT difference in page load times AND that effect the usability of the site and Ill consider a more complex solution to better handle the routing. Otherwise, I like my urls without '.mvc' and so do my customers.

     

    Developer cycles are vastly more expensive than CPU cycles. 

     

    I don't think 6 steps and putting in a config file are all that complicated, but to each his own. It took me about 2 hours to originally set up.  :shrug:

    I also get the additional benefit of being able to re-write all incoming URL's so they appear as I wish them to be.  So for example, if someone comes into www.mysite.com and I want them to only come to mysite.com, a rewriter allows me to do that.

    I was reluctant at first as well to install this, but it was nearly as easy to do as the wildcard mapping and offers me more flexibility.

    I'm the first one in line against premature optimization, but this has benefits beyond performance.

  • Re: MVC On II6 Without the ".mvc" Extension

    01-25-2008, 10:23 PM
    • Member
      93 point Member
    • jamesgeurts
    • Member since 12-11-2003, 1:23 PM
    • Milwaukee, WI
    • Posts 28

     fyi, I setup a step by step "tutorial" for how to setup asp.net mvc on iis6 with pretty urls.  It uses the .mvc extension mapping and isapi_rewrite...

    Thanks

    James Geurts
    Personal Weblog: http://www.biasecurities.com/blogs/jim/
    Work: Property Center
    Filed under: , ,
Page 1 of 1 (12 items)