2010-03-17 95 views
1

我正在開發一個多語種的網站。我通過查詢字符串變量確定所需的語言,例如:http://mydomain.com/default.aspx?lang=enASP.Net Web窗體LoginStatus多個LoginURL - 建議?

我在母版頁中使用了兩個<asp:LoginStatus />控件。我的web.config文件是這樣設置的,用於表單身份驗證。

<authentication mode="Forms"> 
    <forms loginUrl="~/login.aspx" protection="All" timeout="30" 
    name=".ASPXAUTH" path="/" requireSSL="false" 
    slidingExpiration="true" 
    defaultUrl="default.aspx" 
    cookieless="UseDeviceProfile" 
    enableCrossAppRedirects="false"/> 
</authentication> 

目前,當你點擊一個<asp:LoginStatus />你將被重定向到我的登錄頁面和URL會是這個樣子:http://mydomain.com/login.aspx?ReturnUrl=%2fdefault.aspx%3flang%3den

什麼解決方案提供給我,讓我可以追加我的LANG變量到我的login.aspx?取決於哪種語言目前處於活動狀態?

回答

1

login.aspx的代碼隱藏可以HttpServerUtility.UrlDecodeRETURNURL變量。然後使用HttpUtility.ParseQueryString()獲取lang參數。

例如,

HttpUtility.ParseQueryString(HttpUtility.UrlDecode(Request.Params["ReturnUrl"])); 

當然,在現實生活中你會檢查,如果該請求變量甚至存在

HttpUtility.ParseQueryString()

HttpUtility.UrlDecode()

+0

這是非常好的。作品一種享受。謝啦! – TGuimond 2010-03-17 18:19:57

+0

沒問題,隨時。 – kervin 2010-03-17 18:37:47