[英]Get “502 - Web server received an invalid response while acting as a gateway or proxy server” error when opening register page on Azure
[英]Azure Websites - 502 - Web server received an invalid response while acting as a gateway or proxy server
我的Web應用程序在我的本地計算機上正常運行但是當發布到Windows Azure網站時,我在其中一個控制器操作方法上遇到以下錯誤:
502 - Web服務器在充當網關或代理服務器時收到無效響應。 您正在查找的頁面存在問題,無法顯示。 當Web服務器(充當網關或代理)與上游內容服務器聯系時,它從內容服務器收到無效響應。
我使用Elmah捕獲更多信息,我得到:System.ArgumentNullException Value不能為null。 參數名稱:path2
所以當我在我的方法中使用path.combine(path1,path2)時它會引用。 我無法弄清楚發生了什么,輸入文件被正確讀取,並且在檢查輸出目錄時輸出文件正常生成。
關於可能發生什么的任何其他建議?
這是我的動作方法的代碼:
[HttpPost]
public ActionResult ProcessProducts(UploadViewModel model)
{
DateTime startTime = DateTime.UtcNow;
DateTime endTime;
TimeSpan totalTime;
PulProcessor prodManager = new PulProcessor();
string filePath = Path.Combine(Server.MapPath("~/files/incoming"), model.ProductsFileName);
try
{
using (TextReader prodFile = System.IO.File.OpenText(filePath))
{
CsvReader csv = new CsvReader(prodFile);
// map is at end of this file
csv.Configuration.RegisterClassMap<PulMap>();
List<PulProduct> prodList = csv.GetRecords<PulProduct>().ToList();
foreach (var product in prodList)
{
prodManager.ProcessProduct(product);
}
}
}
catch (Exception ex)
{
Elmah.ErrorSignal.FromCurrentContext().Raise(ex);
}
string currentDate = DateTime.UtcNow.ToString("yyyyMMdd");
string productFileName = "PUL" + currentDate + ".txt";
string exceptionsFileName = "PUL" + currentDate + "belowcost.txt";
WriteFile(prodManager.Products, productFileName);
WriteFile(prodManager.BelowCost, exceptionsFileName);
endTime = DateTime.UtcNow;
totalTime = endTime - startTime;
ViewBag.StartTime = startTime.ToString();
ViewBag.EndTime = endTime.ToString();
ViewBag.TotalTime = totalTime.ToString();
ViewBag.TotalOutput = prodManager.Products.Count.ToString();
ViewBag.ProductCounter = prodManager.RecordsProcessed;
ViewBag.FileName = productFileName;
ViewBag.ExFileName = exceptionsFileName;
ViewBag.Exceptions = prodManager.BelowCost.Count.ToString();
return View();
}
private void WriteFile(List<PulFinalProduct> prodList, string fileName)
{
try
{
string filePath = Path.Combine(Server.MapPath("~/files/pul"), fileName);
StreamWriter writer = new StreamWriter(filePath, false);
StringBuilder fileHeader = new StringBuilder();
fileHeader.Append("Inventory Number\t");
fileHeader.Append("MPN\t");
fileHeader.Append("Retail Price\t");
fileHeader.Append("Seller Cost\t");
fileHeader.Append("Buy It Now Price\t");
fileHeader.Append("Starting Bid\t");
fileHeader.Append("ChannelAdvisor Store Price\t");
fileHeader.Append("Quantity\t");
fileHeader.Append("Quantity Update Type\t");
fileHeader.Append("UPC\t");
fileHeader.Append("Weight\t");
fileHeader.Append("Brand\t");
fileHeader.Append("Manufacturer\t");
using (writer)
{
writer.WriteLine(fileHeader.ToString());
foreach (var product in prodList)
{
StringBuilder productLine = new StringBuilder();
productLine.Append(product.InventoryNumber + "\t");
productLine.Append(product.MPN + "\t");
productLine.Append(product.RetailPrice.ToString() + "\t");
productLine.Append(product.SellerCost.ToString() + "\t");
productLine.Append(product.BINPrice.ToString() + "\t");
productLine.Append(product.StartingBid.ToString() + "\t");
productLine.Append(product.CAStorePrice + "\t");
productLine.Append(product.Quantity + "\t");
productLine.Append(product.QUType + "\t");
productLine.Append(product.UPC + "\t");
productLine.Append(product.Weight + "\t");
productLine.Append(product.Brand + "\t");
productLine.Append(product.Manufacturer + "\t");
writer.WriteLine(productLine.ToString());
}
}
}
catch (Exception ex)
{
Elmah.ErrorSignal.FromCurrentContext().Raise(ex);
}
}
以下是Azure Eventlog給我的內容:
Value cannot be null. Parameter name: path2 at System.IO.Path.Combine(String path1, String path2) at Jemco.Web.Controllers.PartsUnlimitedController.ProcessProducts(UploadViewModel model) at lambda_method(Closure , ControllerBase , Object[] ) at System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase controller, Object[] parameters) at System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary`2 parameters) at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters) at System.Web.Mvc.Async.AsyncControllerActionInvoker.<BeginInvokeSynchronousActionMethod>b__36(IAsyncResult asyncResult, ActionInvocation innerInvokeState) at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResult`2.CallEndDelegate(IAsyncResult asyncResult) at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResultBase`1.End() at System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethod(IAsyncResult asyncResult) at System.Web.Mvc.Async.AsyncControllerActionInvoker.AsyncInvocationWithFilters.<InvokeActionMethodFilterAsynchronouslyRecursive>b__3c() at System.Web.Mvc.Async.AsyncControllerActionInvoker.AsyncInvocationWithFilters.<>c__DisplayClass45.<InvokeActionMethodFilterAsynchronouslyRecursive>b__3e() at System.Web.Mvc.Async.AsyncControllerActionInvoker.<>c__DisplayClass30.<BeginInvokeActionMethodWithFilters>b__2f(IAsyncResult asyncResult) at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResult`1.CallEndDelegate(IAsyncResult asyncResult) at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResultBase`1.End() at System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethodWithFilters(IAsyncResult asyncResult) at System.Web.Mvc.Async.AsyncControllerActionInvoker.<>c__DisplayClass1e.<>c__DisplayClass28.<BeginInvokeAction>b__19() at System.Web.Mvc.Async.AsyncControllerActionInvoker.<>c__DisplayClass1e.<BeginInvokeAction>b__1b(IAsyncResult asyncResult) at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResult`1.CallEndDelegate(IAsyncResult asyncResult) at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResultBase`1.End() at System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeAction(IAsyncResult asyncResult) at System.Web.Mvc.Controller.<BeginExecuteCore>b__1d(IAsyncResult asyncResult, ExecuteCoreState innerState) at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResultBase`1.End() at System.Web.Mvc.Controller.EndExecuteCore(IAsyncResult asyncResult) at System.Web.Mvc.Controller.<BeginExecute>b__15(IAsyncResult asyncResult, Controller controller) at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResultBase`1.End() at System.Web.Mvc.Controller.EndExecute(IAsyncResult asyncResult) at System.Web.Mvc.Controller.System.Web.Mvc.Async.IAsyncController.EndExecute(IAsyncResult asyncResult) at System.Web.Mvc.MvcHandler.<BeginProcessRequest>b__4(IAsyncResult asyncResult, ProcessRequestState innerState) at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResultBase`1.End() at System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) at System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult result) at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)
好的,我能夠在這個天藍色的網站上進行遠程調試。 我的控制器動作中的代碼運行正常。 在我得到原始502錯誤后,控制器繼續處理輸入數據,然后寫入輸出文件。 一切正常,我遇到的唯一問題就是在等待處理和加載下一個視圖的同時獲得502頁面。 控制器是否有一定的時間來返回視圖,如果不是這就是為什么我得到502錯誤?
編輯:我很確定我遇到的是超時錯誤,因為我的控制器方法運行時間太長。 我可能無法加速控制器方法,所以我不知道我能做什么。 我不認為我可以或應該更改服務器上的超時設置,所以可能有一些使用ajax可以做的事情,比如每隔一段時間就將狀態更新發送到瀏覽器。 我對此完全陌生,所以我必須做一些研究。
事實證明,整個子程序運行時間太長而無法運行,因此超時因此出現502錯誤。 我通過重寫類來使用SignalR來運行任務來創建文件然后更新用戶關於正在進行的進度來解決這個問題。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.