I have tested a web application I have built using MVC 2 on local servers (both casini and IIS 7.5).
However when I deploy the application to the windows 2008 server standard edition (also running IIS 7.5) I am receiving unexpected results.
The issue is that i have a controller specified to display graphs using Fusion Charts by writing xml data to files.
When the application is deployed, everything works (switching profiles/viewing month-year scale), but when i try to specify a date range the application loads as if nothing happened while making the first xml entry value to a 0.
This does not happen in my local servers, I do not receive any errors at either deployed or local servers.
Here are the relevant part of code that might be able to solve this issue.
The action method:
public ActionResult Index(string clientProfile, string domainProfile, string period, string sDate, string eDate)
{
if (period == "Month")
{
if (!string.IsNullOrEmpty(sDate) && !string.IsNullOrEmpty(eDate))
{
var strXML = seoService.GraphForTrafficCountForDomain(clientProfile, sDate, eDate);
System.IO.File.WriteAllText(AppDomain.CurrentDomain.BaseDirectory + "/FusionCharts/Data/Traffic.xml", strXML);
}
else
{
var strXML = seoService.GraphForTrafficCountForDomain(clientProfile);
System.IO.File.WriteAllText(AppDomain.CurrentDomain.BaseDirectory + "/FusionCharts/Data/Traffic.xml", strXML);
}
}
else if (period == "Year")
{
var strXML = seoService.GraphForVisitsCountForDomainGroupByYear(clientProfile);
System.IO.File.WriteAllText(AppDomain.CurrentDomain.BaseDirectory + "/FusionCharts/Data/Traffic.xml", strXML);
}
return View();
}
The service function:
public string GraphForTrafficCountForDomain(string domain, string sDate, string eDate)
{
var profile = profileService.GetProfileByDomain(domain, null);
string strXML = "";
var StartingDate = DateTime.Parse(sDate);
var EndingDate = DateTime.Parse(eDate);
var data =
repository.FindAll<TrafficData>(x => x.ProfileId == profile.Id && x.Date >= StartingDate && x.Date <= EndingDate).OrderByDescending(d => d.Date).ToList();
strXML += @"<?xml version=""1.0"" encoding=""utf-8"" ?>";
strXML += @"<graph caption="""" subcaption="""" xAxisName=""Month"" yAxisName=""Traffic"" decimalPrecision=""0"" formatNumberScale=""0"">";
for (DateTime date = StartingDate; date.Date <= EndingDate; date = date.AddMonths(1))
{
var startDate = new DateTime(date.Year, date.Month, 1);
var endDate = new DateTime(date.AddMonths(1).Year, date.AddMonths(1).Month, 1).AddDays(-1);
int value = 0;
if (data.Any(x => x.Date >= startDate && x.Date <= endDate))
{
value = data.Where(x => x.Date >= startDate && x.Date <= endDate).Select(d => d.TrafficCount).Sum();
}
strXML += String.Format(@"<set name=""{0}"" value=""{1}"" hoverText=""{2}""/>",
date.ToString("MM-yy"), (value == 0) ? "0" : value.ToString(),
(value == 0) ? "0" : value.ToString() + " " + date.ToString("MM-yy"));
}
strXML += @"</graph>";
return strXML;
}
I am also attaching an image containing the correct output and the wrong output.
The issue was differences between server culture for some reason (even when the server is hosted at the same country as i reside).
the DateTime Object was not parsing correctly.