【发布时间】:2018-09-16 21:16:07
【问题描述】:
我有一个非常简单的 .NET Core 测试应用程序,它在我的开发机器上运行,但在 IIS 10 下在我的服务器上运行时会导致 404。最初,目标是返回一些 JSON 格式的数据库记录,例如 Web 服务.但是,为了缩小错误的搜索范围,我已将应用程序更改为返回单个常量字符串。结果是一样的——在开发机器上工作,在服务器上失败。
在开发机器上,我从 Visual Studio 15.5.7 运行它。我使用 Web Deploy 发布到服务器。
根据其他帖子,我也尝试为 IIS 应用程序池设置“无托管代码”,但没有任何区别。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Newtonsoft.Json;
namespace api.iVoterGuide.com.Controllers
{
[Route("api/ballot")]
public class BallotController: Controller {
// GET api/value -- ballot/542
[HttpGet("{eleck}")]
public IEnumerable<string> Get(short elecK)
{
yield return "[ 1, 2, 3]";
}
}
}
这里是 Startup.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
namespace api.iVoterGuide.com
{
public class Startup
{
public Startup(IConfiguration configuration)
{
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.AddMvc();
}
// 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.UseMvc();
}
}
}
程序.cs
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging;
namespace api.iVoterGuide.com
{
public class Program
{
public static void Main(string[] args)
{
BuildWebHost(args).Run();
}
public static IWebHost BuildWebHost(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.UseStartup<Startup>()
.Build();
}
}
web.config
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<!-- It works either with or without this CORS code -->
<system.webServer>
<handlers accessPolicy="Read, Execute, Script" />
<httpProtocol>
<customHeaders>
<add name="Access-Control-Allow-Origin" value="*" />
</customHeaders>
</httpProtocol>
</system.webServer>
</configuration>
Release.pubxml(已编辑)
<?xml version="1.0" encoding="utf-8"?>
<!--
This file is used by the publish/package process of your Web project. You can customize the behavior of this process
by editing this MSBuild file. In order to learn more about this please visit https://go.microsoft.com/fwlink/?LinkID=208121.
-->
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<WebPublishMethod>FileSystem</WebPublishMethod>
<PublishProvider>FileSystem</PublishProvider>
<LastUsedBuildConfiguration>Release</LastUsedBuildConfiguration>
<LastUsedPlatform>Any CPU</LastUsedPlatform>
<SiteUrlToLaunchAfterPublish />
<LaunchSiteAfterPublish>True</LaunchSiteAfterPublish>
<ExcludeApp_Data>False</ExcludeApp_Data>
<ProjectGuid>e86ba648-3c13-472c-b91c-1d0925762870</ProjectGuid>
<publishUrl>bin\Release\PublishOutput</publishUrl>
<DeleteExistingFiles>True</DeleteExistingFiles>
<TargetFramework>netcoreapp2.0</TargetFramework>
</PropertyGroup>
</Project>
launchSettings.json
{
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:57342/",
"sslPort": 0
}
},
"profiles": {
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"launchUrl": "api/values",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"api.iVoterGuide.com": {
"commandName": "Project",
"launchBrowser": true,
"launchUrl": "api/values",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
},
"applicationUrl": "http://localhost:57343/"
}
}
}
有人有什么建议吗?提前致谢。
编辑:按照另一篇文章(我再也找不到)的建议,我尝试从命令行运行我的应用程序。
D:\wwwroot\api.iVoterGuide.com>dotnet .\api.ivoterguide.com.dll
Error: An assembly specified in the application dependencies manifest (api.ivoterguide.com.deps.json) was not found:
package: 'Microsoft.ApplicationInsights.AspNetCore', version: '2.1.1'
path: 'lib/netstandard1.6/Microsoft.ApplicationInsights.AspNetCore.dll'
This assembly was expected to be in the local runtime store as the application was published using the following target manifest files:
aspnetcore-store-2.0.0-linux-x64.xml;aspnetcore-store-2.0.0-osx-x64.xml;aspnetcore-store-2.0.0-win7-x64.xml;aspnetcore-store-2.0.0-win7-x86.xml
这是服务器上的 --info 结果:
D:\wwwroot\api.iVoterGuide.com>dotnet --info
Microsoft .NET Core Shared Framework Host
Version : 2.0.6
Build : 74b1c703813c8910df5b96f304b0f2b78cdf194d
即使有了这些信息,我也无法解决问题。我已经尝试安装最新的 .NET 版本,在我的 csproj() 中更改 .NET Core 版本,以及其他文章建议的其他几个小改动。
我仍然无法跑步。任何建议。
【问题讨论】:
-
Microsoft 在此处发布了详细的分步说明:docs.microsoft.com/en-us/aspnet/core/host-and-deploy/iis/…您是否遵循了所有这些步骤?
-
感谢两位的帮助。我阅读了有关 dotnet publish 的信息,并且由于它是经过批准的方式,因此我更改为使用它。我会将上面的 pubxml 编辑为我的新文件。不幸的是,我仍然得到 404。如果您有其他想法,我将不胜感激。
-
从命令行运行显示了它缺少程序集的附加信息。我已将详细信息添加到主要帖子的末尾。我仍然无法让它运行。
标签: c# .net-core iis-10 razor-pages