【发布时间】:2017-01-22 01:23:11
【问题描述】:
我正在构建一个 ASP.NET Core MVC Web Api 应用程序,并试图让它在我自己的机器上与 IIS 一起工作。我已经阅读了不同的博客并尝试了不同的东西,但似乎无法让它工作......我的 Winform 客户端在调用 Web api 时只得到 404。通过网络浏览器导航到站点 roo 给我一个 HTTP 错误 403.14 - 禁止。
我正在运行 Windows 10 专业版。安装了 IIS。 ASP.NET Core 服务器托管包已安装
我已经在 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" />
Program.cs
public static void Main(string[] args)
{
var host = new WebHostBuilder()
.UseKestrel()
.UseWebRoot("wwwroot")
.UseContentRoot(Directory.GetCurrentDirectory())
.UseIISIntegration()
.UseStartup<Startup>()
.Build();
host.Run();
}
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();
}
appsettings.json
{
"Logging": {
"IncludeScopes": false,
"LogLevel": {
"Default": "Debug",
"System": "Information",
"Microsoft": "Information"
}
}
}
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%" ]
}
}
IIS 中的网站
IIS 中的应用程序池
我的 IIS
【问题讨论】:
-
尝试指向 inetpub/wwwroot/mywebapi 而不是 inetpub/wwwroot/mywebapi/wwwroot
-
MyWebAPI 和 www 目录的安全设置是什么?
-
对根文件夹 wwwroot 和子文件夹的 IUSR 和 IIS_IUSERS 的完全访问权限。更改到 inetpub/wwwroot/mywebapi 的路径没有区别。在某个地方阅读它必须指向已发布文件夹中的 wwwroot 文件夹。
-
好的,所以我让它工作了......但我不知道为什么!简而言之编程 :) 我创建了一个新的 .net Core Web 项目并使用 IIS 对其进行了测试。它工作得很好,所以我添加了更多..然后更多等等,直到我将所有内容从旧解决方案复制到新解决方案。现在它可以工作了!
-
干得好。您最终指向的是 MyWebAPI 还是 wwwroot?
标签: c# iis asp.net-web-api .net-core asp.net-core-webapi