As the title says, im trying to create an CultureInfo object and save its value in a session. And using that saved CultureInfo object in my method for the returned value. But I get this error, and I cant find the solution! Please take a look.
Class:
public class DateTimeService : WebService
{
[WebMethod(EnableSession = true)]
[ScriptMethod(UseHttpGet = true)]
public string FormatDate(string dateString)
{
DateTime date;
var ci = new CultureInfo(Session["Format"].ToString()); //Culture is not supported.
var formats = Session["Format"].ToString();
DateTime.TryParseExact(dateString, formats, ci, DateTimeStyles.None, out date);
return date.ToString(ci);
}
[WebMethod(EnableSession = true)]
[ScriptMethod(UseHttpGet = true)]
public void SetFormat(string formatString)
{
Session["Format"] = formatString;
}
[WebMethod(EnableSession = true)]
[ScriptMethod(UseHttpGet = true)]
public void SetCulture(string language)
{
if (language == "sv-SE")
{
Session["CultureValue"] = new CultureInfo("sv-SE", false);
}
if (language == "en-US")
{
Session["CultureValue"] = new CultureInfo("en-US", false);
}
}
Global.asax (Where I apply a default Session value):
public class Global : System.Web.HttpApplication
{
protected void Application_Start(object sender, EventArgs e)
{
}
protected void Session_Start(object sender, EventArgs e)
{
Session["Format"] = ("ddMMYYYY");
}
}
Help would be much appreciated!