我正在开发一个具有四个区域的小型系统,当我在Localhost中对其进行测试时,它可以正常工作,但是当我在IIS 7.5中发布它时,它找不到任何区域的路由
我尝试在路由配置中,区域配置中添加名称空间,但它无法以任何方式工作
文件RouteConfig:
namespace Gamma
{
public class RouteConfig
{
public static void RegisterRoutes(RouteCollection routes)
{
//routes.RouteExistingFiles = true;
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
}
}
}
区域:
文件AdministradorAreaRegistration
namespace Gamma.Areas.Administrador
{
public class AdministradorAreaRegistration : AreaRegistration
{
public override string AreaName
{
get
{
return "Administrador";
}
}
public override void RegisterArea(AreaRegistrationContext context)
{
context.MapRoute(
"Administrador_default",
"Administrador/{controller}/{action}/{id}",
new { action = "Index", id = UrlParameter.Optional }
);
}
}
}
文件GestorAreaRegistration
namespace Gamma.Areas.Gestor
{
public class GestorAreaRegistration : AreaRegistration
{
public override string AreaName
{
get
{
return "Gestor";
}
}
public override void RegisterArea(AreaRegistrationContext context)
{
context.MapRoute(
"Gestor_default",
"Gestor/{controller}/{action}/{id}",
new { action = "Index", id = UrlParameter.Optional }
);
}
}
}
文件UsuarioAreaRegistration
namespace Gamma.Areas.Usuario
{
public class UsuarioAreaRegistration : AreaRegistration
{
public override string AreaName
{
get
{
return "Usuario";
}
}
public override void RegisterArea(AreaRegistrationContext context)
{
context.MapRoute(
"Usuario_default",
"Usuario/{controller}/{action}/{id}",
new { action = "Index", id = UrlParameter.Optional }
);
}
}
}
控制器:
应用程序启动
首页
区域:
HomeAdminController 车辆控制器 ProveedorController
HomeGestorController 车辆控制器 ProveedorController
HomeUsuarioController 车辆控制器 ProveedorController
Global.asax
namespace Gamma
{
public class MvcApplication : System.Web.HttpApplication
{
protected void Application_Start()
{
AreaRegistration.RegisterAllAreas();
FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
RouteConfig.RegisterRoutes(RouteTable.Routes);
BundleConfig.RegisterBundles(BundleTable.Bundles);
}
}
}
在帐户控制器中登录
switch (ViewBag.RoleName)
{
case "Admin":
return RedirectToAction("Bienvenida", "HomeAdmin", new { @area = "Administrador" });
case "Usuario":
return RedirectToAction("Bienvenida", "HomeUsuario", new { @area = "Usuario" });
case "Gestor":
return RedirectToAction("Bienvenida", "HomeGestor", new { @area = "Gestor" });
case "Cliente":
return RedirectToAction("Bienvenida", "HomeClientes", new { @area = "Clientes" });
default:
return RedirectToAction("Bienvenida", "HomeUsuario", new { @area = "Usuario" });
在Localhost中工作正常
在IIS中:
错误。 提出诉讼错误。 管理员/ HomeAdmin / Bienvenida
在测试中,他告诉我找不到路线
Error de servidor en la aplicación '/'.
________________________________________
No se encuentra el recurso.
Descripción: HTTP 404. El recurso que está buscando (o una de sus dependencias) se puede haber quitado, haber cambiado de nombre o no estar disponible temporalmente. Revise la dirección URL siguiente y asegúrese de que está escrita correctamente.
Dirección URL solicitada: /Administrador/HomeAdmin/Bienvenida
预先感谢您的帮助
答案 0 :(得分:0)
您是否已用AreaRegistration.RegisterAllAreas();
更新了Global.asax文件
public class MvcApplication : System.Web.HttpApplication
{
protected void Application_Start()
{
AreaRegistration.RegisterAllAreas();
RouteConfig.RegisterRoutes(RouteTable.Routes);
}
}