Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7693927
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T21:12:06+00:00 2026-05-31T21:12:06+00:00

Question: in web.config in section system.web I have <globalization culture=de-ch uiCulture=de-ch requestEncoding=UTF-8 responseEncoding=UTF-8/> What

  • 0

Question:

in web.config
in section

system.web

I have

<globalization culture="de-ch" uiCulture="de-ch" requestEncoding="UTF-8" responseEncoding="UTF-8"/>

What I want is to parse a string like this

"20.03.2012 00:00:00"

to a datetime value

but

DateTime dtAsIs = DateTime.Parse("20.03.2012 00:00:00")

throws an exception

Unfortunately only on the testserver, not on my development system.
I do not have access to the testserver, except to copy the webapp over into a windows share.

I can reproduce the exception like this:

DateTime dtThrowsException = DateTime.Parse("20.03.2012 00:00:00",new System.Globalization.CultureInfo("en-us"));

Whereas it works fine like this:

DateTime dtWorks = DateTime.Parse("20.03.2012 00:00:00",new System.Globalization.CultureInfo("de-ch"));

I checked the ASP page, and there is NO culture set in the asp page

(I mean this:

<% @Page Culture="fr-FR" Language="C#" %>

)

If I set

System.Threading.Thread.CurrentThread.CurrentCulture

and

System.Threading.Thread.CurrentThread.CurrentUICulture

to de-ch at the very start of Page_Load like this

System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("de-ch");
System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo("de-ch");

then it works fine.

The browser language is set to “de-ch”, I checked that.

Can anybody tell my why the thread-culture gets set to English ?

I mean the obvious reason is that the server operating system is English, but I can’t change that one, only settings in web.config.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T21:12:07+00:00Added an answer on May 31, 2026 at 9:12 pm

    The problem seems to be that ASP.NET overwrites the culture even when you explicitly specify it.
    (Like

    DateTime.Parse("Whatever", New System.Globalization.CultureInfo("de-ch"))
    

    )

    one needs to force override it

     New System.Globalization.CultureInfo("de-ch", False)
    

    So in order to make it configurable and change it as few as possible, you need to get the culture from web.config with

    System.Globalization.CultureInfo.CurrentCulture.Name
    

    and then force set it with

     DateTime.Parse("Whatever", New System.Globalization.CultureInfo(System.Globalization.CultureInfo.CurrentCulture.Name, False))
    

    Note the overload with false, it’s necessary, otherwise it doesn’t really work.

    Here is my solution:

    Namespace ASP.NET.Sucks
        Public Class PageWithCorrectPageCulture
            Inherits Web.UI.Page
    
            Protected Sub New()
                System.Threading.Thread.CurrentThread.CurrentCulture = New System.Globalization.CultureInfo(System.Globalization.CultureInfo.CurrentCulture.Name, False)
                System.Threading.Thread.CurrentThread.CurrentUICulture = New System.Globalization.CultureInfo(System.Globalization.CultureInfo.CurrentCulture.Name, False)
            End Sub
    
        End Class
    End Namespace
    

    Then, in the codebehind, replace System.Web.UI.Page with PageWithCorrectPageCulture

    Partial Class whateverpage
        Inherits PageWithCorrectPageCulture
        'Inherits System.Web.UI.Page
    

    And for those who can only copy-pase C#:

    using System;
    using System.Collections;
    using System.Collections.Generic;
    using System.Data;
    using System.Diagnostics;
    namespace ASP.NET.Sucks
    {
        public class PageWithCorrectPageCulture : Web.UI.Page
        {
    
            protected PageWithCorrectPageCulture()
            {
                System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo(System.Globalization.CultureInfo.CurrentCulture.Name, false);
                System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo(System.Globalization.CultureInfo.CurrentCulture.Name, false);
            }
    
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a question about wiring web server controls. From many of the examples
I have little question about how web browser retrieve webpage? I know this User
help out a noob with a simple web development question?? I want to create
I am using externalized config section for appsettings, to be able to have different
We would like to use msbuild to clear the connectionStrings section from a web.config
We have a custom section in my app.config file related to our IoC container
As far as I can tell, any section in a web.config file can be
Question: In my ASP.NET web solution, I have a directory called redlines. Into it,
I have a web app with the default Web.Config file which has 2 child
I'm trying to obtain a reference to the web.config customErrors section. When I use

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.