簡體   English   中英

將ASP.NET Core Web API發布到IIS時出現問題

[英]Issue publishing ASP.NET Core Web API to IIS

我在嘗試將asp.net核心Web API項目部署到IIS時遇到麻煩。 該項目在本地主機上運行良好,但是當部署到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;
}

啟動文件*********

公共類Startup {public Startup(IConfiguration 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();
}

}

程序文件*************

public class Program
{
    public static void Main(string[] args)
    {
        CreateWebHostBuilder(args).Build().Run();
    }

    public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
        WebHost.CreateDefaultBuilder(args)
            .UseStartup<Startup>();
}

500錯誤可能很多。

或者,只需將注冊表項設置為您自己。 (我一直記住它們,因為我一直都在設置它們。)將HKLM \\ Software \\ Microsoft \\ Fusion \\ ForceLog注冊表值設置為1,並將HKLM \\ Software \\ Microsoft \\ Fusion \\ LogPath注冊表值設置為C:\\ FusionLogs或存在。

打開融合日志后,我可以立即在文件夾中看到故障。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM