0
votes

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>();
}
1
Quick one to check, internal server error means code issue follow this guide - Bosco
Do not post code, error message, etc. as images. All relevant information should be in your question as plain text. Additionally, 500 tells us absolutely nothing of value. You need to post the actual exception with stack trace. - Chris Pratt
try to include the code block rather attaching image. - Kiran Maniya
Bosco, I tried the steps in that link, which is the same steps I've been using with no luck. - Thanh

1 Answers

0
votes

It could be a lot for the 500 Error.

Alternatively, just set the Registry keys your self. (I just memorized them, as I set them all the time.) Set HKLM\Software\Microsoft\Fusion\ForceLog registry value to 1 and HKLM\Software\Microsoft\Fusion\LogPath registry value to C:\FusionLogs or some path that exists.

Once I turned on Fusion Logging I could immediately see a failure in my folder.