0

I have an application into application pool of IIS 7. I added a new virtual directory into the application. My application run on http://localhost.com/ and I would like run my virtual directory on http://localhost.com/VirtualDirectory/. The reason why i would like to do that is the virtual directory is used as application. I would like to use Virtual Directory as SubSite. My problem is that i can't access controllers and views under virtual directory. I access it when i change the return result of ActionResult method as "return View("/VirtualDirectory/Views/Home/Index.cshtml");". I don't wanna hard code the VirtualDirectory on every return Action result.

My Route config is:

public static void RegisterRoutes(RouteCollection routes)
        {
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

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

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

I try to make the next change:

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

But when i try to load http://localhost.com/VirtualDirectory I've got the message:

HTTP Error 403.14 - Forbidden The Web server is configured to not list the contents of this directory.

3
  • 1
    you shouldnt need to change the routing at all to run a site under a virtual directory Commented Feb 19, 2014 at 11:10
  • When i not make the change i've got the message: The virtual path '/Views/Home/Index.cshtml' maps to another application, which is not allowed. Commented Feb 19, 2014 at 11:19
  • You was right. You Solve my problem man. Thank you very much. Commented Feb 19, 2014 at 12:03

1 Answer 1

1

You shouldnt need to change anything at all in the routing of your application to run in a virtual directory.

However you will still need to make sure you use relative paths (not absolute / based paths) throughout your application. This is the same with any technology. / always ignores the virtual directory.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.