我有一个WebApp在IIS中的默认AppPool下运行。
在我的webApi项目中,我有一个[HttpGet]方法和一个[HHttpPost]方法。
我有一个自定义的代码,基本上是试图在应用程序位置创建一个文本文件,写入并关闭它。
string path = AppDomain.CurrentDomain.BaseDirectory;
Reporting.PrepareChannel("log", path + ".log");
Reporting.Report("WooOrders", "order created from webhook - Woo order no: ");
Reporting.Shutdown();
将上面的内容放在我的[HttpGet]方法中都很好,但在我的[HttpPost]方法中,它会掉到我的catch块上并返回上面的错误?
我不知道为什么会这样?
在我的[HttpGet]方法中,它在我期望的物理位置创建文件,该物理位置位于我们的“D”驱动器上。
以下是这两种方法的完整代码。虽然我已经部署到我们的生活环境中,但它们还没有被使用。我已经减少了方法,只需创建文件,写入并关闭即可。我暂时已经评论掉了所有其他处理。
[Route("api/woo/createOrder")]
[HttpPost]
public string CreateOrder([FromBody] Models.Order order)
{
try
{
string path = AppDomain.CurrentDomain.BaseDirectory;
Reporting.PrepareChannel("log", path + ".log");
Reporting.Report("WooOrders", "order created from webhook - Woo order no: ");
Reporting.Shutdown();
return "all good";
}
catch (Exception ex)
{
Reporting.Shutdown();
return ex.Message;
}
}
[Route("api/woo/getOrder/{id}")]
[HttpGet]
public string OrderGet([FromUri] string Id)
{
try
{
string path = AppDomain.CurrentDomain.BaseDirectory;
Reporting.PrepareChannel("log", path + ".log");
Reporting.Report("WooOrders", "Get Order ");
Reporting.Shutdown();
return "all good";
}
catch (Exception ex)
{
Reporting.Shutdown();
return ex.Message;
}
}