简体   繁体   中英

ASP.Net MVC 3 Routing with Nested virtual directories, 403 Error

Our current hosting company does not allow Host Header entries for multiple domains to different virtual directories under the one primary domain so we have some code in the Global.asax Begin_Request EventHandler. This works fine so far!

    protected void Application_BeginRequest(object sender, EventArgs e)
    {
        Dictionary<string, string> domains = new Dictionary<string, string>() { { "otherdomain.com", "~/Other/Default.aspx" }, { "seconddomain.com", "~/SECOND/" } };

        string requestedDomain = Request.ServerVariables["SERVER_NAME"].ToLower();

        foreach (var domain in domains.Keys)
        {
            if (requestedDomain.Contains(domain))
                Response.Redirect(domains[domain]);
        }
    }

These work:
www.primarydomain.com - does not match and falls through to ~/Default.aspx
www.otherdomain.com - matches and goes to ~/Other/Default.aspx (the "~/Other/" directory is also a virtual directory and we are using ASP.Net).

This doesn't:
www.seconddomain.com - www.seconddomainname.com/second/ FAILS!!!
The "~/SECOND/" directory is also a virtual directory however we are using ASP.Net MVC 3 with routing, the error we get is "HTTP 403" which would indicate we need to allow a file permissions, the "SECOND" directory is configured as a Virtual Web Directory.

EDIT: Added route

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

Have we missed something very basic, probably, or otherwise is there an overall solution for this type of hosting, routing and ASP.Net configuration?

I haven't encountered a problem like this, but have you tried Server.Transfer instead? I'm not sure if you are trying to do post requests using this route, if so, posted variables are lost using a response.redirect and you may not be able to map to the correct action on the controller that accepts a certain number of parameters.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM