我找到了解决方案...
我保留了 web.config 设置:
<authentication mode="Forms">
<forms loginUrl="~/LogOn" timeout="2880" />
</authentication>
Codeplex 中的 Web.Config
在 RouteConfig.cs
routes.MapRoute(
name: "LogOn",
url: "LogOn/{action}",
defaults: new { controller = "LogOn", action = "SelectLanguage" }
);
并且在 RouteConfig.cs 中的语言路由循环
foreach (var l in Languages)
{
...
routes.MapRoute(
name: "LogOn" + l.Name.ToUpper(),
url: l.Description + "/logon/{action}",
defaults: new { controller = "LogOn", action = "Index", language = l.Description }
);
...
}
codeplex 中的 routeconfig.cs
在控制器底座中
public string URLReferLanguage
{
get
{
string toReturn = ConfigurationManager.AppSettings["DefaultLanguage"];
string language = string.Empty;
string[] tLanguages = ConfigurationManager.AppSettings["Languages"].Split(',');
string urlReferrer = HttpContext.Request.UrlReferrer.AbsolutePath;
if (urlReferrer != null)
{
if (urlReferrer.Length > 5)
{
language = urlReferrer.Substring(1, 5).ToLower();
if (tLanguages.Contains(language))
{
toReturn = language;
}
}
}
return toReturn;
}
}
codeplex 中的 _Controller_Base
在安全层的登录控制器中
public ActionResult SelectLanguage()
{
return Redirect(string.Format("/{0}{1}", base.URLReferLanguage, Request.Url.PathAndQuery));
}
/// <summary>
/// URL: /en-us/LogOn
/// </summary>
/// <returns></returns>
public ActionResult Index()
{
string eMethod = eMethodBase + ".Index[GET]";
using (DataRepositories _dataContext = new DataRepositories())
{
base.InitView(
Resources.View_LogOn_PageTitle,
string.Empty,
specificCssCollection,
specificJSCollection,
dynamicJSCollection,
specificJqueryJSCollection,
jsVariables,
externalCSS,
Meta,
_dataContext,
false,
base.RequestLanguage,
false
);
}
string returnUrl = Request.QueryString["ReturnUrl"];
if (!string.IsNullOrEmpty(returnUrl))
{
ContentData.ReturnUrl = returnUrl;
}
return View(ContentData);
}
codeplex 中的 LogOn 控制器
因此,当用户通过标准角色和成员身份(我的 Provider 继承标准角色)重定向到 LoginForm 时,控制器会分析 UrlRefer 并添加语言来寻址并重定向到它。