Routes in areas not working in MVC / Web forms hyb

2019-07-28 03:07发布

The app has four parts to it and 2 of them are in Areas like so (the solution is just one project fyi):

/Areas/ProjectA/...
/Areas/ProjectB/...

The models, views, and controllers for each are nested in there. The app with loclhost works fine and all the routes behave normally.

The routes do not work on the IIS server since the URL is like:

https://companywebsite.com/subfolder/

The subfolder for the project is messing with the routes.

The Global.asax file is like so:

    protected void Application_BeginRequest(object sender, EventArgs e)
    {
        if (Request.Url.ToString().ToLower().Contains("projecta/default.aspx"))
        {
            Context.Response.StatusCode = 301;
            Context.Response.Redirect("~/ProjectA/Home/Index");
        }

        if (Request.Url.ToString().ToLower().Contains("projectb/home.aspx"))
        {
            Context.Response.StatusCode = 301;
            Context.Response.Redirect("~/ProjectB/Home/Index");
        }
    }

Teh RouteConfig.cs file is like so:

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

        routes.RouteExistingFiles = false;
        routes.IgnoreRoute("projectd/{*pathInfo}");

        // Register[Route] attributes
        routes.MapMvcAttributeRoutes();

        routes.MapPageRoute(
            "WebFormDefault",
            string.Empty,
            "~/index.aspx");

        routes.MapRoute(
            name: "Default",
            url: "{controller}/{action}/{id}",
            defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional });

    }

This is the area registration for Project B:

public class ProjectBAreaRegistration : AreaRegistration 
{
    public override string AreaName 
    {
        get 
        {
            return "ProjectB";
        }
    }

    public override void RegisterArea(AreaRegistrationContext context) 
    {
        context.MapRoute(
            "ProjectB_home",
            "ProjectB/{controller}/{action}/{id}",
            new { controller = "Home", action = "Index", id = UrlParameter.Optional });
    }
}

Issues:

  1. https://loclahost:0123/ProjectA routes correctly but https://companywebsite.com/subfolder/ProjectA routes to https://companywebsite.com/ProjectA/Home/Index with a 404 error.
  2. In ProjectB clicking on a link in htts://companywebsite.com/subfolder/ProjectB/Home/home/error?msg=Not%20Found instead of making an ajax call.

0条回答
登录 后发表回答