繁体   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