Force This Logic To Use The CultureInfo Attached To The Current Thread Instead Of The InvariantCulture?

Nov 18, 2010

I have an ASP .NET Web Forms application that makes use of the 'WebMethod' attribute for making AJAX calls from jQuery. I'm dealing with trying to localize the application so I recently created a web method that looks something like this for testing purposes:

[code]....

I have an HttpModule that is setting the 'CurrentCulture' and 'CurrentUICulture' properties of the current thread to 'pt-BR' (Brazilian Portuguese) at the 'BeginRequest' event.

Client side, I have a jQuery AJAX call to this 'HandleDate' web method that is providing the dateValue parameter as '18/10/2010'. In the 'pt-BR' culture this should evaluate to October 18, 2010 (day/month/year date format).

When I execute this I'm getting back an error indicating that the 'System.Web.Script.Serialization.ObjectConverter' is blowing up stating that '18/11/2010' is not a valid value for DateTime. The stack trace included with the error indicates that this was thrown by the 'System.ComponentModel.DateTimeCoverter.ConvertFrom' method, which accepts the object to be converted in addition to a CultureInfo object representing the culture that should be applied during the conversion.

I fired up Reflector and it appears that the 'ObjectConverter' is invoking the 'DateTimeConverter' using CultureInfo.InvariantCulture instance, which I think is the problem.

How can I force this logic to use the CultureInfo attached to the current thread instead of the InvariantCulture?

View 1 Replies


Similar Messages:

Access The Current Thread's Context Using HttpContext.Current?

Mar 11, 2010

I have a static class with serveral static methods. In these methods, I'm trying to access the current thread's context using HttpContext.Current. For example:

var userName = HttpContext.Current.User.Identity.Name;

However, when I do that, I receive a NullReferenceException, the infamous "Object reference not set to an instance of an object."

View 3 Replies

C# - Set HttpContext.Current.User From Thread.CurrentPrincipal?

May 17, 2010

I have a security manager in my application that works for both windows and web, the process is simple, just takes the user and pwd and authenticates them against a database then sets the Thread.CurrentPrincipal with a custom principal. For windows applications this works fine, but I have problems with web applications.

After the process of authentication, when I'm trying to set the Current.User to the custom principal from Thread.CurrentPrincipal this last one contains a GenericPrincipal. Am I doing something wrong? This is my code:

Login.aspx

[code]....

View 5 Replies

Cross-thread Operation Not Valid: Accessed From A Thread Other Than The Thread It Was Created On

Apr 2, 2010

I want to remove checked items from checklistbox (winform control) in class file method which i am calling asynchronously using deletegate. but it showing me this error message:-

Cross-thread operation not valid: Control 'checkedListBox1' accessed from a thread other than the thread it was created on.

i have tried invoke required but again got the same error. Sample code is below:

[code]....

View 1 Replies

Getting Website's URL Without HttpContext.Current (running In Background Thread)?

Aug 3, 2010

Bit of a long shot, but is there a way in ASP.NET to dynamically get the website's URL [URL] when there is no HttpContext.Current available.

There is no HttpContext because the code is running in a background thread* (but under the ASP.NET AppDomain). I have a background process that sends emails out every evening, and needs to include the Web address, but I don't want to hard code it because of deployments and testing (it changes from [URL] to[URL] and then to [URL] for the live site).

View 2 Replies

What Is The Result Of Setting The Current Thread's Culture Code

Jun 2, 2010

what is the result of setting the current thread's culture code?

I understand if I use the resource file it will pull label's/strings from the .resx file.

What else? Will it effect my date/money formatting also?

View 3 Replies

C# - Accessing HttpSessionState (HttpContext.Current.Session) From Another Thread?

Nov 25, 2010

We have a web site which implements a central HttpSessionState management in App_Code like this:

[code]...

All of this worked fine ultil we needed to implement a time consuming process in a new thread...
In the second thread HttpContext.Current.Session is null (we know its because the current context its different between threads) so everything fails :

Investigating we found that you could pass the session from one thread to another like this:

[code]...

View 2 Replies

Access System.Web.Http.Current.Response From A Within A Thread?

Jul 16, 2010

I have a ASP.NET page with a WebMethod that creates an object and runs one of the object's methods in a new thread.I need to access the System.Web.HttpContext.Current.Response.ContentType property from within this thread. Each time I (try to) access it, I receive a NullReferenceException.

View 1 Replies

Localization :: Assign Culture To Current Thread When Http Is Stateless?

Feb 5, 2010

When I was localizing my web application I got one strange doubt.

In the first request i set current thread's current culture to user chosen culture. It worked fine for that particular request. But when i browsed for other page, server rendered content in default english culture. I think the reason meight be "http is stateless" means current request is served by a thread whose culture was set properly. Send request will be serverd another thread which does not about previous thread. So we should once again assign culture to this thread. Localization can be done by setting culture to a session variable.

So my question is what is the benifit that we get by setting culture to current thread. With setting to thread we can show the page in user desired language.

View 2 Replies

Setting A Default Value -- Presentation Logic Or Business Logic?

Jun 18, 2010

I was wondering if setting a default value for a SelectList is considered to be presentation logic or business logic? For example, if a requirement is that an Employee cannot be saved without a Location, but 99% of the time the location that would be selected is a particular item -- say Atlanta. Because of this, the location SelectList should be defaulted to Atlanta when ever a entry screen for a new employee is displayed. Should I be defaulting the location in the model or in the view-model? One thing I realized is that the unit tests become awkward because in both cases, I'd be forced to test against a location that will always be present in production but I cannot create a unit test with my own test dataunless "Atlanta" was in the set of locations being used in the test.

View 4 Replies

Visual Studio :: Debug A Multi Thread Program To See Local Variables Of Each Thread Using 2008

Jan 27, 2010

How can we debbug a multi-thread program to see local variables of each thread using visual studio 2008.

View 1 Replies

Architecture :: How Can Thread Update A Variable Shared With The Main Thread

Nov 24, 2010

I'm new to threading and have used it successfully, but limited. I can spawn a thread and have the main thread reference variables in the spawned thread, but I don't know how to allow the spawned thread to reference (and update) variables in the main thread.

Any example threading code I've seen on the web appears to be WAY more complicated than what I do, so I am unable to understand or integrate into my code.

Here is a quick example of how I use threading:

[code].....

View 3 Replies

Localization :: What Is CultureInfo Datatype

Aug 17, 2010

I ve seen more Sites but i can't able to understand guys

Ex:("CultureInfo culture = new CultureInfo( "hi-IN" );")

View 3 Replies

What Are The Differences Between Currently Executing .NET Thread And Win32 Thread

Mar 24, 2010

I am reading the Asp.net security documentation on msdn.I come across these tow terms and get really confused.

# WindowsIdentity = WindowsIdentity.GetCurrent()

which returns the identity of the security context of the currently executing Win32 thread.

# Thread = Thread.CurrentPrincipal

which returns the principal of the currently executing .NET thread which rides on top of the Win32 thread.

View 1 Replies

C# - Lock Thread.sleep Not Working With .NET Thread?

Jun 25, 2010

I have a password page and when someone enters an incorrect password I want to simply foil a brute force attack by having

bool isGoodPassword = (password == expected_password);

lock (this)
{
if (!isGoodPassword)
Thread.Sleep(2000);
}
I would expect that this would allow all correct passwords without stalling, but if one user enters a bad password another successful password from a different user would also be blocked. However, the lock doesn't seem to lock across ASP.NET threads.

View 4 Replies

Web Forms :: Use Thread.sleep Method For A Particular Thread?

Aug 27, 2010

I want a example of multithreading .i want to use it in a web form not on console.i am using C#.net .and how to use thread.sleep method for a particular thread.

View 5 Replies

How To Store DateTime Object With CultureInfo

Mar 2, 2011

Does the DateTime object stores the CultureInfo with it, or you need to use the Formatter to format the DateTime according to current culture ?

I have a class property that retuns a DateTime. Within that property I am setting the DateTime object with current culture information using CultureInfo object. Below is the code for class property I am using:

public DateTime PrintedQuoteDate {
get{
DateTime printQuoteDate = DateTime.Today;
// cInfo = CultureInfo object
return Convert.ToDateTime(printQuoteDate , cInfo);
}
}

So my question is when I will use the above property in my code, will it have the corrosponding culture information that I am setting in its get method, or I will have to use the same CONVERT code for formatting date time. The restriction here is that the Property should return only DateTime type.

View 2 Replies

Localization :: CultureInfo.DisplayName Going Sami?

Jun 4, 2010

Why is CultureInfo.DisplayName in [Sami][1] all of a sudden? I use it to display a list of country names. Not a good idea perhaps but it worked until recently and I'm quite sure it was in Swedish (I guess it could have been English.)

View 2 Replies

Creating A NumberFormat For An Existing .NET CultureInfo In Application?

Mar 22, 2010

I want to format my numbers throughout the application in a consistent way, no matter what culture is chosen. In fact, it's "non-standard" even for the basic culture that we're using.

I want to format "{1500.50:c}" as: '1500.50', but the standard for my culture 'nl-NL', is: '€ 1.500,00'. We don't have the user-rights, since it's a webapplication, to register custom cultures, therefore we're looking for a runtime solution.

We want a "set and forget" solution. Not a Util class with static (extension) methods, but an application wide solution, so we can continue to use the standard .ToString("c"), or ToString("N") logic, which would follow our custom rules. This would be to alter the .NumberFormat of the Culture, but how? Everything seems to be readonly.

View 2 Replies

Globalization - Can You Filter The Allowable CultureInfo Types For A Website?

Apr 27, 2010

I could definitely accomplish what I want with a custom handler, but I was hoping it would be possible to adjust the web.config to define allowable cultures. Basically, I have a website that has resource files for a number of languages. I would like to deploy the same website to different domains with different configurations specifying the default cultures. I know I can set a specific culture to be used in the web.config, but can I also specify multiple cultures? Even though I have English language resource files, I don't want a visitor from the US to certain domains to see the English version, but I can't fix the site for a single culture, either.

View 1 Replies

Localization :: System.Globalization.CultureInfo() Change The Month Of Date?

Jan 25, 2011

I am Using javascript calander to select date into textbox. I have Set the Date Format MM-DD-YYYY . Now when i convert this text string to DateTime then my Actual month of date is changed.

IFormatProvider theCultureInfo = new System.Globalization.CultureInfo("en-GB", true);
DateTime date = DateTime.ParseExact(txtDate.Text, "mm-dd-yyyy", theCultureInfo);

For example If i Put in Text Box 2-12-2011 (12 Feb 2011) Then After Converting It will 12-01-2011 00:02:00 .

View 2 Replies

VS 2008 C# - Attached Image

Jul 23, 2010

i described my problem in attached image

View 3 Replies

SQL Server :: Database Cannot Be Attached?

Mar 30, 2011

I had a database created in sql server 2005.In order to upload my site i unistalled sql 2005 n installed sql2008. N now im not able to attach my database.Its giving error access denied.Im using windows 7 home. I ran sql 2008 as administrator also.Then too its giving the same error.Now how can i attach my database?

What is the correct way of having the latest copy of db? Im trying to attach my db from the App_data folder of my prjct .Will it contain all the latest tables i created in it?

View 3 Replies

How To Send A Mail With Some Attached Files To It

Aug 13, 2010

When I try to send a mail with some attached files to it. I get this error: Could not find file 'c:windowssystem32inetsrv1.gif'.

code:

[Code]....

[Code]....

View 4 Replies

Web Forms :: Download All Attached File Functionality?

Sep 6, 2010

I want to develop one functionality for Download All Attachment files in Single file format like (.ZIP or .RAR) in my web application (asp.net 3.5).How can I achive this task ?

View 2 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved