ASP.Net MVC切换培养编译初始加载后 [英] ASP.Net MVC switching Cultures after compile for initial load

查看:170
本文介绍了ASP.Net MVC切换培养编译初始加载后的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个混合ASP.Net Web窗体/ MVC应用程序。在MVC页面/景色之一,我把它渲染了一堆使用ToShortDateString()和ToLongDateString()日期。这些正常工作的大部分时间,但我第一次编译应用程序后,装载看来,他们的格式不正确。

I have a hybrid ASP.Net web forms/MVC app. On one of the MVC "pages"/views, I have it render a bunch of dates using the ToShortDateString() and ToLongDateString(). These work correctly most of the time, but the first time I load the view after compiling the app, they are formatted incorrectly.

我跟踪下来,并检查当前线程的文化。对于99%的时间是EN-US,但对MVC视图的第一次加载后,编译它被设置为EN-GB。如果我之后立即重新载入页面,又回到了EN-US。

I traced this down and checked the current thread's culture. For 99% of the time it's en-US, but on the first load of the MVC view after compiling it is set to en-GB. If I reload the page immediately after that, it's back to en-US.

我曾尝试在web.config文件中的Culture和UICulture设置为en-US,迫使它是正确的,但没有运气。

I have tried setting the culture and uiculture in the web.config file to en-US to force it to be correct, but no luck.

任何人有这个什么想法? MVC中的错误?

Anyone have any ideas on this one? Bug in MVC?

编辑(额外的code和尝试):
即使我去完全落水,其中包括该基类的看法

Edit (additional code and attempts): Even if I go completely overboard and include this in the base class of the view

public class DNViewPage<T> : ViewPage<T> where T : class
    {

        protected override void OnInit(EventArgs e) {
            base.OnInit(e);
            CultureInfo cultureInfo = new CultureInfo("en-US");
            this.Culture = "en-US";
            this.UICulture = "en-US";
            Thread.CurrentThread.CurrentUICulture = cultureInfo;
            Thread.CurrentThread.CurrentCulture = cultureInfo;
        }

        protected void Page_Load(object sender, EventArgs e) {
            CultureInfo cultureInfo = new CultureInfo("en-US");
            this.Culture = "en-US";
            this.UICulture = "en-US";
            Thread.CurrentThread.CurrentUICulture = cultureInfo;
            Thread.CurrentThread.CurrentCulture = cultureInfo;
        }

        protected override void InitializeCulture() {

            CultureInfo cultureInfo = new CultureInfo("en-US");
            this.Culture = "en-US";
            this.UICulture = "en-US";
            Thread.CurrentThread.CurrentUICulture = cultureInfo;
            Thread.CurrentThread.CurrentCulture = cultureInfo;

            base.InitializeCulture();
        }
    }

和包含这个在web.config

and include this in the web.config

<globalization requestEncoding="utf-8" responseEncoding="utf-8" uiCulture="en-US" culture="en-US"/>

这在.aspx文件的标题

and this in the header of the .aspx file

<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Culture="en-US" UICulture="en-US"

同样,这仅在初始加载编译code,当第一次加载页面后。其他Web窗体页不会受到影响,即使他们从System.Web.Mvc.ViewPage下降。所有后续加载正确对待文化。只是改变了.aspx文件不会导致这种情况,C#code已被编译导致此。

Again, this is only on the initial load after compiling the code, when that page first loads. Other web forms pages are unaffected, even if they descend from System.Web.Mvc.ViewPage. All subsequent loads treat the culture correctly. Just changing the .aspx file doesn't cause this, the c# code has to be compiled to cause this.

更多的数据:
我有它追查到Render方法。 Render方法之前,文化为en-US,之后是EN-GB(只能再次在编译后的初始页面加载)。

More data: I have it tracked down to the Render method. Before the Render method, the culture is en-US and afterwards it is en-GB (again only on initial pageload after compilation).

推荐答案

这竟然是通过一个过时的,第三方.dll文件的依赖造成的。有一次,我跟踪下来,并得到了更新.dll文件,一切都和好如初。

This turned out to be caused by an a dependency on an out of date, third party .dll. Once I tracked it down, and got the updated .dll, all was good again.

这篇关于ASP.Net MVC切换培养编译初始加载后的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆