StringFormat issue.

J

Jens Jensen

Hello,
I have a webservice that performs some financial calculations. I use
String.Format("{0:n}) to presents the numbers in the culture specific
format.
This works fine on my dev machine which runs win xp in Danish.(running the
webservice locally and consumming it there).

My windows 2003 production server has language/culture Us english.
When i consume my webservice remotely from there, the formating goes all
wrong.

There is a setting under Language and regional options under control panel
that have changed to danish. This does not help me get my expected format .

Can someone tell what i'm doing wrong?

Many thanks
JJ
 
N

Nicholas Paldino [.NET/C# MVP]

Jens,

You might have to set the culture in your web.config file. Here is a
post online which details how to do that (as well as other culture related
info in ASP.NET):

http://www.dotnetjunkies.com/Tutorial/17E26271-E212-4248-965F-4B33D2EDD38B.dcik

On top of that, I hope that the numbers you are formatting are part of
other text that you are returning, and not the numbers themselves. If
anything, I would think you would pass a number back and let the client
decide how to format them.

Hope this helps.
 
J

Jani Järvinen [MVP]

Hi Jens,
My windows 2003 production server has language/culture Us english.
When i consume my webservice remotely from there, the formating goes all
wrong.

Like Nicholas already pointed out, your best bet is probably to choose a
culture for your application and set that in web.config.

The reason you are seeing this change in cultures in your production server
is that (assuming you are using IIS as your web server) the so-called
regional settings are set on per-user basis. When IIS runs your web service,
it does so in the context of another user account, which you can configure
with the IIS Admin tool.

For a reference, you might also want to check this document about ASP.NET
application Worker Process Isolation Mode:

http://www.microsoft.com/technet/pr...ee3-ec31-4148-afab-b6e089a0300b.mspx?mfr=true

And, in case you are totally unsure about the configuration on your
production server, create a simple .ASPX page that contains the following:

----------------------------
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs"
Inherits="_Default" %>

<head runat="server">
<title>Who Am I?</title>
</head>
<body>
<h1>Who Am I?</h1>
<pre><%= GetCurrentUserInfo() %></pre>
</body>
</html>
----------------------------

And for the page.aspx.cs file, type in the following code:

----------------------------
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text;
using System.Security.Principal;

public partial class _Default : System.Web.UI.Page
{
public string GetCurrentUserInfo()
{
StringBuilder info = new StringBuilder();
WindowsIdentity currentUser = WindowsIdentity.GetCurrent();
info.Append("Username: "+currentUser.Name + "\r\n");
info.Append("SID: " + currentUser.User.Value + "\r\n");
return info.ToString();
}
}
----------------------------

At runtime, the GetCurrentUserInfo() method will report data similar to the
following:

----------------------------
Who Am I?

Username: SAPPHIRE\ASPNET
SID: S-1-5-21-2052711402-412623190-839572195-1021
----------------------------

Hope this helps!

--
Regards,

Mr. Jani Järvinen
C# MVP
Helsinki, Finland
(e-mail address removed)
http://www.saunalahti.fi/janij/
 
J

Jens Jensen

Thank you all,
This was very helpful.. I will go experiement with all these qualified
helps.

Thanks
JJ
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top