我的项目中有两个区域Admin
和Client
。
RouteConfig.cs
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
name: "Default",
url: "{language}/{controller}/{action}/{id}",
defaults: new { language = "en-US", controller = "Home", action = "Index", id = UrlParameter.Optional },
namespaces: new[] { "Testing.Controllers" }
);
}
目前的结果:
[✓] localhost
[✓] localhost/en-us
[✓] localhost/zh-hk
[✗] localhost/admin
[✗] localhost/client
我希望我能做到这样的事情:
localhost - Home Page (Default Language)
localhost/en-us - Home Page (English)
localhost/zh-hk - Home Page (Traditional Chinese)
localhost/admin/en-us - Admin Area Home Page (English)
localhost/admin/zh-hk - Admin Area Home Page (Traditional Chinese)
localhost/client/en-us - Client Area Home Page (English)
localhost/client/zh-hk - Client Area Home Page (Traditional Chinese)
答案 0 :(得分:1)
您需要在通用路由寄存器
之前注册区域在通用路线之前添加<script>
function runClock(remainingTime) {
$('.clock').FlipClock(remainingTime, {
clockFace: 'DailyCounter',
countdown: true,
onStop: function () {
$(".timerContainer").css('display', 'none');
}
});
}
</script>
<?php
$now = new DateTime('now');
$tm = new DateTime('2017-12-22 12:00:00');
$remainingTime = $tm->getTimestamp() - $now->getTimestamp();
if ($remainingTime > 0) {
echo "<script> runClock(" . $remainingTime . ");</script>";
}
?>
AreaRegistration.RegisterAllAreas();
您的管理区域注册,
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
AreaRegistration.RegisterAllAreas();
routes.MapRoute(
name: "Default",
url: "{language}/{controller}/{action}/{id}",
defaults: new { language = "en-US", controller = "Home", action = "Index", id = UrlParameter.Optional },
namespaces: new[] { "Testing.Controllers" }
);
}
客户区注册,
public class AdminAreaRegistration : AreaRegistration
{
public override string AreaName
{
get
{
return "Admin";
}
}
public override void RegisterArea(AreaRegistrationContext context)
{
context.MapRoute(
"Admin_default",
"Admin/{language}/{controller}/{action}/{id}",
new { language = "en-US", controller = "Home", action = "Index", id = UrlParameter.Optional }
);
}
}