2017-08-28 56 views
-1

我有一個ASP.NET MVC我正在從VS2015運行時工作很好,但在IIS 8.5上部署後,出現錯誤訪問使用GET的控制器時的標題。下面有一個堆棧跟蹤:索引超出了數組的範圍 - 部署後的ASP.NET MVC

[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 我不知道爲什麼會這樣......

UPDATE(下面的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

+0

發佈您的'ShowInvoice' ActionMethod – adiga

+0

非常懷疑這是一個與部署id相關的問題 - 與相關的已編寫和正在執行的代碼相關的代碼 - 請張貼引發異常的代碼 – GregH

+0

I用代碼更新了問題 –

回答

0

看來該問題是由服務器.net全球化選項生成的,因爲服務器以不同格式返回從SQL中提取的數據。我在服務器上設置了與開發計算機上相同的全球化,現在它可以工作。