gpt4 book ai didi

c# - Azure 网站 - 502 - Web 服务器在充当网关或代理服务器时收到无效响应

转载 作者:行者123 更新时间:2023-11-30 17:47:03 26 4
gpt4 key购买 nike

我的 Web 应用程序在本地计算机上运行良好,但当发布到 Windows Azure 网站时,我在其中一种 Controller 操作方法上收到以下错误:

502 - Web 服务器在充当网关或代理服务器时收到无效响应。您要查找的页面有问题,无法显示。当 Web 服务器(充当网关或代理)联系上游内容服务器时,它从内容服务器收到无效响应。

我使用 Elmah 捕获更多信息,我得到:系统参数NullException值不能为空。参数名称: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 事件日志给我的内容:

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) 

好的,我能够在这个 azure 的站点上进行远程调试。我的 Controller 操作中的代码运行良好。在我收到原始 502 错误后, Controller 继续处理输入数据,然后写入输出文件。一切工作正常,我遇到的唯一问题是在等待它处理和加载下一个 View 时出现 502 页面。 Controller 是否有一定的时间来返回 View ,如果没有,这就是我收到 502 错误的原因?

编辑:我很确定我遇到的是超时错误,因为我的 Controller 方法运行时间太长。我可能无法加速 Controller 方法,所以我不确定我能做什么。我不认为我可以或应该更改服务器上的超时设置,因此也许可以使用 ajax 来完成某些操作,例如每隔一段时间向浏览器发送状态更新。我对此完全陌生,所以我必须做一些研究。

最佳答案

事实证明,整个子例程运行时间太长,并且超时,因此出现 502 错误。我通过重写类以使用 SignalR 运行任务来创建文件,然后向用户更新正在进行的进度来解决这个问题。

关于c# - Azure 网站 - 502 - Web 服务器在充当网关或代理服务器时收到无效响应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25194224/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com