我最近将我的 mvc3 本地化结构从 lang 作为子域 (fr.domain.com) 切换为 lang 作为路径 (domain.com/fr)。
一切正常,但自动重定向到帐户登录。
假设我没有通过身份验证,我尝试访问 domain.com/fr/test 我被重定向到 domain.com/Account/LogOn?ReturnUrl...
如何配置我的网站以便重定向到 /fr/Account/LogOn?ReturnUrl...
编辑 :
我使用路线映射
routes.MapRoute(
"DefaultLocalized", // Route name
"{lang}/{controller}/{action}/{id}", // URL with parameters
new { lang = "en", controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
, new { lang = "fr" }
);
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
);
解决方案:这是我基于 developer10214 建议的解决方案实现
public ActionResult LogOn()
{
if (System.Web.HttpContext.Current.Request.Url.Query.Contains("%2ffr%2f") && System.Threading.Thread.CurrentThread.CurrentUICulture.TwoLetterISOLanguageName != "fr")
return Redirect("/fr/Account/LogOn" + System.Web.HttpContext.Current.Request.Url.Query);
LogOnModel model = new LogOnModel() { UserName = "", Password = "" };
return View(model);
}