该应用程序有四个部分,其中2个在像这样的区域(解决方案只是一个项目fyi):
/Areas/ProjectA/...
/Areas/ProjectB/...
每个模型,视图和控制器都嵌套在那里。 loclhost的应用程序运行正常,所有路由都正常运行。
路由在IIS服务器上不起作用,因为URL类似于:
https://companywebsite.com/subfolder/
该项目的子文件夹正在弄乱路线。
Global.asax 文件是这样的:
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 文件是这样的:
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 });
}
这是项目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 });
}
}
的问题: