Hosting a virtual directory under MVC

Last post 10-30-2009 2:46 PM by jamie-jones. 8 replies.

Sort Posts:

  • Hosting a virtual directory under MVC

    09-11-2008, 6:09 PM
    • Member
      28 point Member
    • daggmano
    • Member since 06-19-2008, 12:25 AM
    • Sydney, Australia
    • Posts 23

    I'm setting up am ASP.NET MVC site onto a development server, and would like to run a wiki (Screwturn Wiki) as a subdirectory of the site.  I have set up 'wiki' as a virtual directory in IIS7 (WinServer 2008), and added 'routes.IgnoreRoute("wiki");' to Global.asax, but when I browse to that virtual directory I get a Compilation Error as it looks for Microsoft.Web.Mvc.dll, from the web.config file of my MVC site.

    Am I able to completely bypass MVC for a virtual subdirectory?  (I would have thought that IIS would redirect before any application layer, but I guess not).

     Thanks in advance.

  • Re: Hosting a virtual directory under MVC

    09-12-2008, 9:58 AM
    Answer
    • Member
      368 point Member
    • maartenba
    • Member since 01-23-2008, 1:27 PM
    • Belgium
    • Posts 76

    Try to add the following configuration directives into the web.config of your /wiki/ folder:

    <?xml version="1.0"?>

    <configuration>

    <system.web>

    <pages>

    <namespaces>

    <remove namespace="System.Web.Mvc"/>

    <remove namespace="System.Web.Mvc.Ajax"/>

    <remove namespace="Microsoft.Web.Mvc"/>

    <remove namespace="System.Web.Routing"/>

    </namespaces>

    </pages>

    <httpHandlers>

    <remove verb="*" path="*.mvc" />

    </httpHandlers>

    <httpModules>

    <remove name="UrlRoutingModule" />

    </httpModules>

    </system.web>

    </configuration>

    Visit my blog at http://blog.maartenballiauw.be

    Order my book ASP.NET MVC 1.0 Quickly via http://www.packtpub.com/asp-net-model-view-controller-1-0-quickly/book
  • Re: Hosting a virtual directory under MVC

    09-14-2008, 9:21 PM
    • Member
      28 point Member
    • daggmano
    • Member since 06-19-2008, 12:25 AM
    • Sydney, Australia
    • Posts 23

    That did (most of) the trick - thank you.  Now I'm running into another issue.  In Global.asax.cs, I have added

    routes.IgnoreRoute("wiki");

    or a number of variations on that ("wiki*", "wiki/", etc).

    This has allowed the wiki virtual subdir to be accessed, but now all the routes generated using Html.ActionLink<>() have the form

    http://localhost/wiki?controller=Cont&action=Index

    Somehow "wiki" has overtaken my app!!!

     

    Any ideas as to what is going on here?

     Thanks again.

  • Re: Hosting a virtual directory under MVC

    09-15-2008, 1:50 AM
    • Member
      368 point Member
    • maartenba
    • Member since 01-23-2008, 1:27 PM
    • Belgium
    • Posts 76

    Can you post your full route table here?

    Visit my blog at http://blog.maartenballiauw.be

    Order my book ASP.NET MVC 1.0 Quickly via http://www.packtpub.com/asp-net-model-view-controller-1-0-quickly/book
  • Re: Hosting a virtual directory under MVC

    09-15-2008, 2:16 AM
    • Member
      28 point Member
    • daggmano
    • Member since 06-19-2008, 12:25 AM
    • Sydney, Australia
    • Posts 23

    Sure - it's pretty complex (tongue held securely in cheek...)

       routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
       routes.IgnoreRoute("wiki/{*path}");

       routes.MapRoute(
        "Default",                                              // Route name
        "{controller}/{action}/{id}",                           // URL with parameters
        new { controller = "Home", action = "Index", id = "" }  // Parameter defaults
       );

    It's that second line - I've tried quite a few options, but either I get no access to the wiki subdir or my ActionLinks go spastic.  I could hard code all links, but that sort of defeats the purpose.  I'm using MVC Preview 5 (from Codeplex) if that makes difference.

  • Re: Hosting a virtual directory under MVC

    09-15-2008, 9:51 AM
    Answer
    • Member
      368 point Member
    • maartenba
    • Member since 01-23-2008, 1:27 PM
    • Belgium
    • Posts 76

    Change:

    routes.IgnoreRoute("wiki/{*path}");

    To:

    routes.IgnoreRoute("{*path}", new { path = @"wiki\/(.*)" });

    This forces the path to be something starting with wiki/.

    Visit my blog at http://blog.maartenballiauw.be

    Order my book ASP.NET MVC 1.0 Quickly via http://www.packtpub.com/asp-net-model-view-controller-1-0-quickly/book
  • Re: Hosting a virtual directory under MVC

    09-15-2008, 5:43 PM
    • Member
      28 point Member
    • daggmano
    • Member since 06-19-2008, 12:25 AM
    • Sydney, Australia
    • Posts 23

    Maartenba, I owe you a beer!

    Thanks for all your help.

  • Re: Hosting a virtual directory under MVC

    09-16-2008, 2:00 AM
    • Member
      368 point Member
    • maartenba
    • Member since 01-23-2008, 1:27 PM
    • Belgium
    • Posts 76

    Guess that beer will be warm before it arrives :-(

    No problem :-)

    Visit my blog at http://blog.maartenballiauw.be

    Order my book ASP.NET MVC 1.0 Quickly via http://www.packtpub.com/asp-net-model-view-controller-1-0-quickly/book
  • Re: Hosting a virtual directory under MVC

    10-30-2009, 2:46 PM
    • Member
      4 point Member
    • jamie-jones
    • Member since 06-15-2008, 12:05 PM
    • Posts 11

    I am having this issue. I am trying to install the time tracking starter on a virtual directory with a MVC app on the root.


    I have called the virtual directory Time.


    Below is the web.config from the time app

    <?xml version="1.0"?>
    <configuration xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0">
      <connectionStrings>
        <add name="aspnet_staterKits_TimeTracker" connectionString="Server=208.78.24.53,14333;Database=databaseName;Uid=jamiejon;Password=Fia84grapu;User Instance=true" />
        <remove name="LocalSqlServer"/>
        <add name="LocalSqlServer" connectionString="Data Source=.\SQLExpress;Integrated Security=True;AttachDBFilename=|DataDirectory|TimeTracker.mdf;User Instance=true" />
      </connectionStrings>
      <location path="Time" inheritInChildApplications="false">
      <system.web>
        <pages>
          <namespaces>
            <remove namespace="System.Web.Mvc"/>
            <remove namespace="System.Web.Mvc.Ajax"/>
            <remove namespace="Microsoft.Web.Mvc"/>
            <remove namespace="System.Web.Routing"/>
          </namespaces>
        </pages>
        <siteMap defaultProvider="AspNetXmlSiteMapProvider" enabled="true">
          <providers>
            <clear />
            <add name="AspNetXmlSiteMapProvider"
    type="System.Web.XmlSiteMapProvider, System.Web, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
    siteMapFile="web.sitemap"
    securityTrimmingEnabled="true"  />
          </providers>
        </siteMap>
        <authentication mode="Forms">
          <forms loginUrl="~/TimeTracker/login.aspx"/>
        </authentication>
        <compilation debug="false" />
        <customErrors mode="Off"/>
        <machineKey decryptionKey="AutoGenerate,IsolateApps"/>
        <roleManager enabled="true" >
        </roleManager>
          <httpHandlers>
              <remove verb="*" path="*.mvc" />
          </httpHandlers>
        <httpModules>
          <remove name="UrlRoutingModule" />
        </httpModules>
      </system.web>
    </location>
    </configuration>

    <?xml version="1.0"?>

    <configuration xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0">

      <connectionStrings>

        <add name="aspnet_staterKits_TimeTracker" connectionString="Server=208.78.24.53,14333;Database=databaseName;Uid=jamiejon;Password=Fia84grapu;User Instance=true" />

        <remove name="LocalSqlServer"/>

        <add name="LocalSqlServer" connectionString="Data Source=.\SQLExpress;Integrated Security=True;AttachDBFilename=|DataDirectory|TimeTracker.mdf;User Instance=true" />

      </connectionStrings>

      <location path="Time" inheritInChildApplications="false">


      <system.web>

        <pages>

          <namespaces>


            <remove namespace="System.Web.Mvc"/>

            <remove namespace="System.Web.Mvc.Ajax"/>


            <remove namespace="Microsoft.Web.Mvc"/>

            <remove namespace="System.Web.Routing"/>


          </namespaces>

        </pages>

        <siteMap defaultProvider="AspNetXmlSiteMapProvider" enabled="true">

          <providers>

            <clear />

            <add name="AspNetXmlSiteMapProvider"

    type="System.Web.XmlSiteMapProvider, System.Web, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"

    siteMapFile="web.sitemap"

    securityTrimmingEnabled="true"  />

          </providers>

        </siteMap>

        <authentication mode="Forms">

          <forms loginUrl="~/TimeTracker/login.aspx"/>

        </authentication>

        <compilation debug="false" />

        <customErrors mode="Off"/>

        <machineKey decryptionKey="AutoGenerate,IsolateApps"/>

        <roleManager enabled="true" >

        </roleManager>

          <httpHandlers>


              <remove verb="*" path="*.mvc" />

          </httpHandlers>

        <httpModules>

          <remove name="UrlRoutingModule" />

        </httpModules>

      </system.web>

    </location>

    </configuration>



    Using this in the Global.asax for the root mvc app

    routes.IgnoreRoute("{folder}/{*pathInfo}", new { folder = "time" });

    I am still getting the 404 error, the ignore doesn't seem to be working, can any one offer advice.

    Requested URLhttp://myurl:80/Time/Account/LogOn?ReturnUrl=%2fTime%2fTimeTracker%2fTimeEntry.aspx
    Physical PathC:\HostingSpaces\ myusername\time\wwwroot\Account\LogOn

Page 1 of 1 (9 items)