开发者

Possible Bug - Asp.net Routing Localization strange problem with Thread

I have two Pages A and B. Both should display a Text using the appropriate Global Resource depending on the Culture setting in Web.Conf.

On Page A I'm able to visualize the text accordingly to the Culture setting (so in 开发者_开发问答this case French).

Page A has also a Link which use GetUrl to create an Url (Routing) to Page B

<asp:HyperLink 
           runat="server" 
           Text='<%# Eval("Title") %>' 
           NavigateUrl='<%# GetRouteUrl("TopicHub", new {TitleUrl = Eval("TitleUrl")}) %>'>
</asp:HyperLink>

At the moment of visit Page B I'm not able to see the Literal in French anymore and Text in English is applied (Default value). The strange thing is if I open Page B directly in the Browser the Literal displays in French.

So I debugged the Global.asax.cs and I found out the at the moment of Clicking the Link created with GetRouteUrl the var Thread.CurrentThread.CurrentCulture and CurrentUICulture are in English and not in French as for my Web.Config.

MY Questions are:

  • What could be the problem here? Maybe a bug?
  • Any idea how to fix it?

I'm running out of ideas so as last thought would be to force in Global.asax.cs the Thread.CurrentThread.CurrentCulture using the value in Web.Conf.

Please let me know your thoughts on this. Thanks!

Page A:

<asp:Literal ID="uxLatestGuides" 
             runat="server" 
             Text="<%$ Resources:Global, LatestGuides %>" />

Page B:

<asp:Literal ID="uxLatestGuides" 
             runat="server" 
             Text="<%$ Resources:Global, LatestGuides %>" />

Global.asax.cs

protected void Application_BeginRequest(object sender, EventArgs e)
{
  var check1 = Thread.CurrentThread.CurrentCulture;
  var check2 = Thread.CurrentThread.CurrentUICulture;
}

Web.Config

<?xml version="1.0"?>
    <configuration>
        <system.web>
            <pages enableViewState="false" theme="Cms-FE-00" >
            </pages>
            <globalization culture="fr" uiCulture="fr"/>
        </system.web>
    </configuration>


I was able to find the solution to this problem.

Analyzing the Global.asax.cs Routes I notice the virtual URL topic/{TitleUrl} that will map to the physical Url ~/Cms/FrontEndCms/CategoryList.aspx

 routes.MapPageRoute("TopicHub", "topic/{TitleUrl}", "~/Cms/FrontEndCms/CategoryList.aspx");

In my specif case I had the Web.Config file in ~/Cms/FrontEndCms/ so when a link would be created on the a Routed URL page like mysite.com/topic/my-page the Web.Config would not be in the right place but in another Folder so my Culture setting would not apply.

The solution was to move Web.Config to the ROOT for my website so it will apply on all Routes. Hopes can help some one else.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜