【发布时间】:2015-10-31 03:19:22
【问题描述】:
我有以下项目结构。我有两个家庭和帐户控制器,一个在测试区域内,一个在路由级别项目。现在从区域登录后,我想重定向区域的主页索引,但它会将我重定向到路由级别主页索引。
考场注册地图路线
public override void RegisterArea(AreaRegistrationContext context)
{
context.MapRoute(
"Test_default",
"Test/{controller}/{action}/{id}",
new { controller = "Account", action = "Login", id = UrlParameter.Optional },
namespaces: new[] { "MVCAreaSample.Areas.Test.Controllers" }
);
}
基础地图路线
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Account", action = "Login", id = UrlParameter.Optional },
namespaces: new[] { "MVCAreaSample.Controllers" }
);
区域重定向操作方法
[HttpPost]
public ActionResult Login(TestModel test)
{
var candidateContext = "LoginContext";
FormsAuthenticationTicket authTicket = new FormsAuthenticationTicket(2, candidateContext, DateTime.Now, DateTime.Now.AddMinutes(60), true, "Manjay");
string encryptedTicket = FormsAuthentication.Encrypt(authTicket);
HttpCookie authCookie = new HttpCookie(FormsAuthentication.FormsCookieName, encryptedTicket);
//Check required for code contracts.
if (System.Web.HttpContext.Current != null)
{
System.Web.HttpContext.Current.Response.Cookies.Add(authCookie);
if (System.Web.HttpContext.Current.Session != null)
System.Web.HttpContext.Current.Session["LoginContext"] = candidateContext;
}
return RedirectToAction("Index", "Home");
}
我尝试在路线中给出区域名称。它适用于这种情况。但是假设我在两个级别都有适当的身份验证逻辑而不是
RedirectToAction("Index", "Home", new { area = "Test" });
它会给我基本级别的登录页面。
【问题讨论】:
标签: c# asp.net asp.net-mvc asp.net-mvc-4 asp.net-mvc-areas