![](/img/trans.png)
[英]Error on starting .NET Core Web API on IIS: "Application is running inside IIS process but is not configured to use IIS server"
[英]Deploying .NET Core Web API to IIS Server
我创建了我的第一个.Net Core Web API 并尝试将其部署到远程 IIS 服务器。 我在前端使用了一个create-react-app
项目。
当我在本地调试并与.Net Core WEB API 通信时,它工作正常:
https://localhost:5001/api/notes
I use https://myapp.eastus.cloudapp.azure.com
as my public URL (here myapp is an example), and everything looks fine on browser that the front end pages load correctly.
但是当我通过获取get
测试后端 API 时
https://myapp.eastus.cloudapp.azure.com/api/notes
我得到了404 。
web.config
Core Web API 构建文件夹:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<location path="." inheritInChildApplications="false">
<system.webServer>
<handlers>
<add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModuleV2" resourceType="Unspecified" />
</handlers>
<aspNetCore processPath="dotnet" arguments=".\myapp.dll" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" hostingModel="inprocess" />
</system.webServer>
</location>
</configuration>
并反应web.config
文件:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.webServer>
<staticContent>
<remove fileExtension=".js" />
<mimeMap fileExtension=".js" mimeType="application/javascript; charset=UTF-8" />
</staticContent>
<rewrite>
<rules>
</rules>
</rewrite>
</system.webServer>
</configuration>
更新:
我的DbContext
EF Core 实例:
using Microsoft.Extensions.Configuration;
using Microsoft.EntityFrameworkCore;
namespace Notes.DB
{
public class AppDbContext : DbContext
{
protected readonly IConfiguration Configuration;
public DbSet<Note> Notes { get; set; }
public AppDbContext(IConfiguration configuration)
{
Configuration = configuration;
}
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
optionsBuilder.UseSqlServer(
Configuration.GetConnectionString("myDb1"));
}
}
}
并且, appsettings.json
in.Net Core 项目:
{
"AppSettings": {
"Secret": ""
},
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft": "Warning",
"Microsoft.Hosting.Lifetime": "Information"
}
},
"AllowedHosts": "*",
"ConnectionStrings": {
"myDb1": 'I generated this string from Azure SQL Database'
}
}
我的Controller
代码:
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using Notes.Core;
using Notes.DB;
namespace myApp.Controllers
{
[ApiController]
[Route("[controller]")]
[Bind("Id,Username,Value")]
public class NotesController : ControllerBase
{
private readonly ILogger<NotesController> _logger;
private INotesServices _notesSerives;
private readonly AppDbContext _context;
public NotesController(ILogger<NotesController> logger, INotesServices notesSerives, AppDbContext context)
{
_logger = logger;
_notesSerives = notesSerives;
_context = context;
}
[HttpGet("", Name = "GetAllNote")]
public IActionResult GetAllNote()
{
return Ok(_notesSerives.GetAllNote());
}
}
}
我做错了什么? 如何调试这个?
如果您使用 HTTPS(使用 TLS 进行身份验证),如果 TLS 失败,您将不会收到任何响应。 所以出现这个问题的原因可能是你要访问的站点不支持HTTPS,或者URL不存在。
可以先尝试使用http访问,如果http可以访问成功则应该是证书验证问题。 如果使用http时仍然出现404,那么.Net Core Web API应该没有成功部署到Z5E265ACF46064EFB27. 也可能是因为您使用了错误的 URL。 关于“Host ASP.NET Core on Windows with IIS”的信息,可以参考这个链接: https://docs.microsoft-aspnetcored/en-us/aspnet/? -5.0
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.