I am having trouble trying to deploy my asp.net core web API project to IIS. The project works fine localhost, but when deployed to IIS I get internal 500 error on my complex query controller, and could not get any response for controllers that were scaffold-ed. However, the pre-built values controller response back fine.
I am pulling data from mssql db.
Is my controller class wrong? or my sql connection not working in IIS?
Can someone please help point me in the right direction?
Here are screenshots of my controller, startup, and program files.
I've tried everything available on the web.
Here are screenshots of my files.
My controller Complex Query *****
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;
}
Startup File *********
public class Startup { public Startup(IConfiguration configuration) { Configuration = configuration; }
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();
}
}
Program File *************
public class Program
{
public static void Main(string[] args)
{
CreateWebHostBuilder(args).Build().Run();
}
public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.UseStartup<Startup>();
}