【问题标题】:Issue publishing ASP.NET Core Web API to IIS将 ASP.NET Core Web API 发布到 IIS 的问题
【发布时间】: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


【解决方案1】:

500 错误可能很多。

或者,只需自行设置注册表项。 (我只是记住了它们,因为我一直在设置它们。)将 HKLM\Software\Microsoft\Fusion\ForceLog 注册表值设置为 1,将 HKLM\Software\Microsoft\Fusion\LogPath 注册表值设置为 C:\FusionLogs 或某个路径存在。

打开 Fusion Logging 后,我可以立即在我的文件夹中看到故障。

【讨论】:

    猜你喜欢
    • 2018-02-02
    • 2018-02-28
    • 2017-01-16
    • 2018-10-26
    • 1970-01-01
    • 2021-01-30
    • 2019-05-12
    • 2021-07-18
    • 1970-01-01
    相关资源
    最近更新 更多