索引超出了数组的范围 - 部署后的ASP.NET MVC

时间:2017-08-28 12:50:29

标签: asp.net-mvc iis-8

我有一个ASP.NET MVC我正在努力从VS2015运行时效果很好,但在IIS 8.5上部署后,我在访问使用GET的控制器时会出现标题错误。下面是堆栈跟踪:

    [IndexOutOfRangeException: Index was outside the bounds of the array.]
    Accounting.Controllers.IesiriController.ShowInvoice(String tipDocument, String seria, Nullable`1 nrDocument, String dataDocument, String clientName) +12673
    lambda_method(Closure , ControllerBase , Object[] ) +352
    System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary`2 parameters) +229
    System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters) +35
    System.Web.Mvc.Async.AsyncControllerActionInvoker.<BeginInvokeSynchronousActionMethod>b__39(IAsyncResult asyncResult, ActionInvocation innerInvokeState) +39
    System.Web.Mvc.Async.WrappedAsyncResult`2.CallEndDelegate(IAsyncResult asyncResult) +67
    System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethod(IAsyncResult asyncResult) +42
    System.Web.Mvc.Async.AsyncInvocationWithFilters.<InvokeActionMethodFilterAsynchronouslyRecursive>b__3d() +72
    System.Web.Mvc.Async.<>c__DisplayClass46.<InvokeActionMethodFilterAsynchronouslyRecursive>b__3f() +385
    System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethodWithFilters(IAsyncResult asyncResult) +42
    System.Web.Mvc.Async.<>c__DisplayClass2b.<BeginInvokeAction>b__1c() +38
    System.Web.Mvc.Async.<>c__DisplayClass21.<BeginInvokeAction>b__1e(IAsyncResult asyncResult) +185
    System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeAction(IAsyncResult asyncResult) +38
    System.Web.Mvc.Controller.<BeginExecuteCore>b__1d(IAsyncResult asyncResult, ExecuteCoreState innerState) +29
    System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +65
    System.Web.Mvc.Controller.EndExecuteCore(IAsyncResult asyncResult) +52
    System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +36
    System.Web.Mvc.Controller.EndExecute(IAsyncResult asyncResult) +38
    System.Web.Mvc.MvcHandler.<BeginProcessRequest>b__5(IAsyncResult asyncResult, ProcessRequestState innerState) +43
    System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +65
    System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) +38
    System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +656
    System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +143

目标框架是4.5 我不知道为什么会这样......

更新(以下是ShowInvoice代码):

    public ActionResult ShowInvoice(string tipDocument, string seria, int? nrDocument, string dataDocument, string clientName)
            {
                //get company data
                ViewBag.CompanyName = System.Configuration.ConfigurationManager.AppSettings["CompanyName"];
                ViewBag.CodFiscal = System.Configuration.ConfigurationManager.AppSettings["CodFiscal"];
                ViewBag.NrRegCom = System.Configuration.ConfigurationManager.AppSettings["NrRegCom"];
                ViewBag.Adresa = System.Configuration.ConfigurationManager.AppSettings["Adresa"];
                ViewBag.Adresa2 = System.Configuration.ConfigurationManager.AppSettings["Adresa2"];
                ViewBag.IBAN = System.Configuration.ConfigurationManager.AppSettings["IBAN"];
                ViewBag.Banca = System.Configuration.ConfigurationManager.AppSettings["Banca"];

                if ((tipDocument == null) || (seria == null) || (nrDocument == null) || (dataDocument == null))
                {
                    return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
                }
                string dataDoc2 = dataDocument.Split(' ')[0];
                string dataDoc = dataDoc2.Split('/')[1] + "/" + dataDoc2.Split('/')[0] + "/" + dataDoc2.Split('/')[2];
                string dataDocTVA = dataDoc2.Split('/')[2] + "-" + dataDoc2.Split('/')[0] + "-" + dataDoc2.Split('/')[1];
                //get Note
                string queryNote = "SELECT TOP(1) * FROM Iesiris i "
                                + "INNER JOIN Clients c ON i.ClientID = c.ID "
                                + "INNER JOIN Articoles a ON i.ArticolID = a.ID "
                                + "INNER JOIN SeriiFacturis s ON i.SeriaID = s.ID "
                                + "WHERE i.NrDocument = " + nrDocument + " AND i.DataDocument = '" + dataDocument + "' AND s.Seria = '" + seria + "'";
                var returnedNote = db.Database.SqlQuery<IesiriVMDetails>(queryNote).ToList();
                ViewBag.note = returnedNote[0].Note;
                int ClientID = returnedNote[0].ClientID;

                //get date delegat
                ViewBag.Delegat = returnedNote[0].Delegat;
                ViewBag.DelegatSeria = returnedNote[0].DelegatSeria;
                ViewBag.DelegatNumar = returnedNote[0].DelegatNumar;
                ViewBag.DelegatEliberat = returnedNote[0].DelegatEliberat;
                ViewBag.DelegatAuto = returnedNote[0].DelegatAuto;

                //get emis de
                ViewBag.fullName = returnedNote[0].EmisDe;
                ViewBag.ci = returnedNote[0].CI;

                //get date client
                string queryClient = "SELECT TOP(1) * FROM Clients WHERE ID = " + ClientID;
                var returnedClient = db.Database.SqlQuery<Clients>(queryClient).ToList();
                if (returnedClient[0].VatPayer == true) 
                {
                    ViewBag.codFiscal = "RO" + returnedClient[0].FiscalCode;
                }
                else
                {
                    ViewBag.codFiscal = returnedClient[0].FiscalCode;
                }
                /*
                //get user data
                string queryUser = "SELECT TOP(1) * FROM AspNetUsers WHERE UserName = '" + User.Identity.Name + "'";
                var returnedUser = db.Database.SqlQuery<Users>(queryUser).ToList();
                ViewBag.fullName = returnedUser[0].FirstName + " " + returnedUser[0].LastName;
                ViewBag.ci = returnedUser[0].CI;
                */

                ViewBag.nrRegCom = returnedClient[0].Regnumber;
                ViewBag.adresa = returnedClient[0].Address;
                ViewBag.contBancar1 = returnedClient[0].BankAcc1;
                ViewBag.banca1 = returnedClient[0].BankName1;

                string scadenta = returnedNote[0].ScadentaDocument.ToString();
                string scadentaDoc2 = scadenta.Split(' ')[0];
                ViewBag.scadentaDocument = scadentaDoc2.Split('/')[1] + "/" + scadentaDoc2.Split('/')[0] + "/" + scadentaDoc2.Split('/')[2];

                ViewBag.tipDocument = tipDocument;
                ViewBag.dataDocument = dataDoc;
                ViewBag.nrDocument = nrDocument;
                ViewBag.seria = seria;
                ViewBag.clientName = clientName;
                string query = "SELECT * FROM Iesiris i "
                                + "INNER JOIN Clients c ON i.ClientID = c.ID "
                                + "INNER JOIN Articoles a ON i.ArticolID = a.ID "
                                + "INNER JOIN SeriiFacturis s ON i.SeriaID = s.ID "
                                + "WHERE i.NrDocument = " + nrDocument + " AND i.DataDocument = '" + dataDocument + "' AND s.Seria = '" + seria + "'";
                IEnumerable<IesiriVMDetails> data = db.Database.SqlQuery<IesiriVMDetails>(query);

                //get Total and total TVA
                decimal total = data.Sum(item => item.Valoare);
                decimal totalTVA = data.Sum(item => item.ValoareTVA);
                ViewBag.totalGeneral = total + totalTVA;
                ViewBag.total = total;
                ViewBag.totalTVA = totalTVA;

                //verifica TVA la incasare vanzator pentru adaugarea notei
                int cui = Int32.Parse(returnedClient[0].FiscalCode.ToString());
                RTVAI.IService1 obj_rtvai = new RTVAI.Service1Client();
                string tvaIncasare = obj_rtvai.checkVATonCollection(cui, dataDocTVA);

                if (tvaIncasare == "DA")
                {
                    ViewBag.TVAincasare = "TVA la incasare";
                }

                return View(data.ToList());
            }

我想知道为什么这在调试中运行时效果很好....一旦部署,我也会在其他操作中得到此错误...这与ShowInvoice不同

1 个答案:

答案 0 :(得分:0)

似乎该问题是由服务器.net全局化选项生成的,因为服务器以不同的格式返回从SQL中提取的数据。我在服务器上设置了与开发计算机相同的全球化,现在它可以运行。