本地和部署的 MVC 2 应用程序之间的差异

发布于 2024-10-12 23:31:24 字数 3440 浏览 1 评论 0原文

我已经测试了在本地服务器(casini 和 IIS 7.5)上使用 MVC 2 构建的 Web 应用程序。 但是,当我将应用程序部署到 Windows 2008 服务器标准版(也运行 IIS 7.5)时,我收到了意外的结果。

问题是我指定了一个控制器,通过将 xml 数据写入文件来使用 Fusion Charts 显示图形。

部署应用程序后,一切正常(切换配置文件/查看月年比例),但是当我尝试指定日期范围时,应用程序加载,就像在将第一个 xml 条目值设置为 0 时什么也没发生一样。

这种情况不会发生在我的本地服务器中,我在部署的服务器或本地服务器上都没有收到任何错误。

以下是可能能够解决此问题的相关代码部分。

操作方法:

 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();
 }

服务功能:

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 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.

Output Image

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

忘羡 2024-10-19 23:31:24

问题是由于某种原因,服务器文化之间存在差异(即使服务器托管在我居住的同一国家/地区)。

DateTime 对象未正确解析。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文