定義Owin LOGINPATH我有一個MVC 5網站提供本地化航線"en-US"
定義爲MVC 5如何與本地化路線
routes.MapRoute(
name: "Default",
url: "{culture}/{controller}/{action}/{id}",
defaults: new { culture = CultureHelper.GetDefaultCulture(), controller = "Home", action = "Index", id = UrlParameter.Optional }
);
其中默認的培養結果。
問題出現在啓動時,我有使用LOGINPATH屬性來定義登錄URL,它被設置一次,它總是會使用提供的值,例如如果「/ zh-cn/Account/Login」是指定值,則爲默認文化。然後,我嘗試使用UrlHelper類的經驗,一些神奇的希望,但結果顯然是相同的:
var httpContext = HttpContext.Current;
if (httpContext == null) {
var request = new HttpRequest("/", "http://example.com", "");
var response = new HttpResponse(new StringWriter());
httpContext = new HttpContext(request, response);
}
var httpContextBase = new HttpContextWrapper(httpContext);
var routeData = new RouteData();
var requestContext = new RequestContext(httpContextBase, routeData);
UrlHelper helper = new UrlHelper(requestContext);
var loginPath = helper.Action("Login", "Account");
// Enable the application to use a cookie to store information for the signed in user
app.UseCookieAuthentication(new CookieAuthenticationOptions
{
AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
LoginPath = new PathString(loginPath)
});
我的問題是:有沒有辦法破解這個機制來動態檢索當前文化還是我我被迫將當前文化設置爲cookie,並且當我重定向到登錄頁面時,在呈現頁面之前使用cookie值設置當前文化?
謝謝
嗨,謝謝你的回答!我會在接下來的日子裏嘗試一下,我會讓你知道! – s0nica
完美。什麼最好的片段見過。爲我節省了很多時間。和... @拉菲的回答是提高你的答案(如他所說):) – abzarak