Chr*_*ian 6 c# iis asp.net-web-api .net-core asp.net-core-webapi
我正在构建一个ASP.NET核心MVC Web Api应用程序,我正试图让它在我自己的机器上使用IIS.我已经阅读了不同的博客并尝试了不同的东西,但似乎无法让它工作......我的Winform客户端在调用Web API时只获得404.通过网络浏览器导航到网站roo给我一个HTTP错误403.14 - 禁止.
我正在运行Windows 10 Pro.IIS已安装.已安装ASP.NET Core Server Hosting Bundle
我在IIS中添加了该网站.应用程序池设置为"无管理代码".在VS2015中,我将网站发布到本地文件夹.我将该文件夹的内容复制到IIS正在查找的网站文件夹中.然后我会期望它工作,但它没有:(
这是我的设置:
web.config中
<system.webServer>
<handlers>
<add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModule" resourceType="Unspecified" />
</handlers>
<directoryBrowse enabled="true"/>
<aspNetCore processPath="%LAUNCHER_PATH%"
arguments="%LAUNCHER_ARGS%"
stdoutLogEnabled="true"
stdoutLogFile=".\logs\aspnetcore-stdout"
forwardWindowsAuthToken="false" />
Run Code Online (Sandbox Code Playgroud)
Program.cs中
public static void Main(string[] args)
{
var host = new WebHostBuilder()
.UseKestrel()
.UseWebRoot("wwwroot")
.UseContentRoot(Directory.GetCurrentDirectory())
.UseIISIntegration()
.UseStartup<Startup>()
.Build();
host.Run();
}
Run Code Online (Sandbox Code Playgroud)
StartUp.cs
public Startup(IHostingEnvironment env)
{
var builder = new ConfigurationBuilder()
.SetBasePath(env.ContentRootPath)
.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
.AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true)
.AddEnvironmentVariables();
Configuration = builder.Build();
}
Run Code Online (Sandbox Code Playgroud)
appsettings.json
{
"Logging": {
"IncludeScopes": false,
"LogLevel": {
"Default": "Debug",
"System": "Information",
"Microsoft": "Information"
}
}
}
Run Code Online (Sandbox Code Playgroud)
project.json:
{
"dependencies": {
"Business": "1.0.0-*",
"Data": "1.0.0-*",
"Microsoft.AspNetCore.Mvc": "1.1.0",
"Microsoft.AspNetCore.Routing": "1.1.0",
"Microsoft.AspNetCore.Server.IISIntegration": "1.1.0",
"Microsoft.AspNetCore.Server.IISIntegration.Tools": "1.1.0-preview4-final",
"Microsoft.AspNetCore.Server.Kestrel": "1.1.0",
"Microsoft.Extensions.Configuration.EnvironmentVariables": "1.1.0",
"Microsoft.Extensions.Configuration.FileExtensions": "1.1.0",
"Microsoft.Extensions.Configuration.Json": "1.1.0",
"Microsoft.Extensions.Logging": "1.1.0",
"Microsoft.Extensions.Logging.Console": "1.1.0",
"Microsoft.Extensions.Logging.Debug": "1.1.0",
"Microsoft.Extensions.Options.ConfigurationExtensions": "1.1.0",
"Microsoft.NETCore.App": "1.1.0"
},
"tools": {
"Microsoft.AspNetCore.Server.IISIntegration.Tools": "1.1.0-preview4-final"
},
"frameworks": {
"netcoreapp1.0": {
"imports": [
"dotnet5.6",
"portable-net45+win8"
]
}
},
"buildOptions": {
"emitEntryPoint": true,
"preserveCompilationContext": true
},
"runtimeOptions": {
"configProperties": {
"System.GC.Server": true
}
},
"publishOptions": {
"include": [
"wwwroot",
"**/*.cshtml",
"appsettings.json",
"web.config"
]
},
"runtimes": {
"win10-x64": {}
},
"scripts": {
"postpublish": [ "dotnet publish-iis --publish-folder %publish:OutputPath% --framework %publish:FullTargetFramework%" ]
}
}
Run Code Online (Sandbox Code Playgroud)
IIS中的网站
IIS中的应用程序池
我的IIS
将 IIS 指向MyWebAPI而不是 at MyWebAPI/wwwroot。否则您将收到“HTTP 错误 403.14 - 禁止”错误。
这是GitHub 上的演示应用程序。它使用的设置与您答案中的应用程序使用的设置相同。当我将它发布到我的 IIS 时,它起作用了,如下所示:
dotnet publish -o C:\inetpub\wwwroot\sandbox\
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5839 次 |
| 最近记录: |