【发布时间】:2019-12-28 02:36:37
【问题描述】:
我在尝试将我的 asp.net 核心 Web API 项目部署到 IIS 时遇到问题。该项目在 localhost 上运行良好,但是当部署到 IIS 时,我在复杂的查询控制器上收到内部 500 错误,并且无法为脚手架编辑的控制器获得任何响应。但是,预建值控制器响应良好。
我正在从 mssql 数据库中提取数据。
我的控制器类错了吗?还是我的 sql 连接在 IIS 中不起作用?
有人可以帮我指出正确的方向吗?
这是我的控制器、启动和程序文件的屏幕截图。
我已经尝试了网络上可用的所有内容。
这是我的文件的屏幕截图。
我的控制器复杂查询 *****
public IEnumerable<SalesOrder> GetSalesOrder()
{
var salesOrders = _context.SalesOrder.Include("LineItem").Select(s => new SalesOrder
{
// Sales orders
id = s.id,
orderId = s.orderId,
creationDate = s.creationDate,
lastModifiedDate = s.lastModifiedDate,
legacyOrderId = s.legacyOrderId,
orderFulfillmentStatus = s.orderFulfillmentStatus,
orderPaymentStatus = s.orderPaymentStatus,
sellerId = s.sellerId,
username = s.username,
priceSubtotal = s.priceSubtotal,
paymentMethod = s.paymentMethod,
paymentReferenceId = s.paymentReferenceId,
shipToName = s.shipToName,
addressLine = s.addressLine,
city = s.city,
stateOrProvince = s.stateOrProvince,
postalCode = s.postalCode,
countryCode = s.countryCode,
phoneNumber = s.phoneNumber,
email = s.email,
shippingCarrierCode = s.shippingCarrierCode,
estimatedDeliveryDate = s.estimatedDeliveryDate,
dateAdded = s.dateAdded,
// Line items
LineItems = s.LineItems.Select(l => new LineItem
{
id = l.id,
lineItemId = l.lineItemId,
legacyItemId = l.legacyItemId,
sku = l.sku,
title = l.title,
lineItemCost = l.lineItemCost,
currency = l.currency,
quantity = l.quantity,
dateAdded = l.dateAdded,
orderId = l.orderId
})
}).OrderByDescending(d => d.creationDate).ToList();
return salesOrders;
}
启动文件*********
公共类启动 { 公共启动(IConfiguration 配置) { 配置=配置; }
public IConfiguration Configuration { get; }
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
services.AddDbContext<ApplicationDbContext>(options => options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")));
services.AddCors();
services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
app.UseCors(builder =>
builder.WithOrigins(Configuration["ApplicationSettings:Client_URL"]).AllowAnyHeader().AllowAnyMethod());
app.UseAPIKeyMessageHandlerMiddleware();
app.UseMvc();
}
}
程序文件 *************
public class Program
{
public static void Main(string[] args)
{
CreateWebHostBuilder(args).Build().Run();
}
public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.UseStartup<Startup>();
}
【问题讨论】:
-
快速检查,内部服务器错误意味着代码问题遵循此guide
-
请勿以图片形式发布代码、错误信息等。所有相关信息都应以纯文本形式出现在您的问题中。此外,500 绝对没有告诉我们任何有价值的信息。您需要使用堆栈跟踪发布实际异常。
-
尝试包含代码块而不是附加图像。
-
Bosco,我尝试了该链接中的步骤,这与我一直使用的步骤相同,但没有运气。
标签: asp.net asp.net-core iis asp.net-web-api