gpt4 book ai didi

c# - Asp.net 核心部署不能在服务器上运行,但可以在机器上运行

转载 作者:太空狗 更新时间:2023-10-29 20:26:50 25 4
gpt4 key购买 nike

我正在尝试在服务器上部署一个 asp.net 核心应用程序。我已经完成了以下步骤。

首先,这是一个Windows Server 2012 r2环境,是一个全新的虚拟机。

  1. 构建虚拟机
  2. 更新所有 ms 更新
  3. 添加 iis 角色
  4. 确保机器上安装了 asp.net 3.5 和 4.5
  5. 确保安装了 http 重定向和静态内容
  6. 安装 .net 核心包
  7. 从 Visual Studio 发布自包含应用程序(项目名称 Web)
  8. 将其添加到服务器上的文件夹中。
  9. 尝试从 web.exe 运行

我看到控制台应用程序打开时说现在正在监听:http://localhost:500010. 我去 http://localhost:5000从这台机器上的 chrome 获取 404 not found。

我在 Windows 10 本地机器上执行步骤 7、8、9 和 10,我得到了我的应用程序。

project.json

  {
"dependencies": {
"AutoMapper": "5.1.1",
"EntityFramework": "6.1.3",
"Microsoft.ApplicationInsights.AspNetCore": "1.0.0",
"Microsoft.AspNetCore.Diagnostics": "1.0.0",
"Microsoft.AspNetCore.Mvc": "1.0.0",
"Microsoft.AspNetCore.Razor.Tools": {
"version": "1.0.0-preview2-final",
"type": "build"
},
"Microsoft.AspNetCore.Server.IISIntegration": "1.0.0",
"Microsoft.AspNetCore.Server.Kestrel": "1.0.0",
"Microsoft.AspNetCore.StaticFiles": "1.0.0",
"Microsoft.Extensions.Configuration.EnvironmentVariables": "1.0.0",
"Microsoft.Extensions.Configuration.Json": "1.0.0",
"Microsoft.Extensions.Logging": "1.0.0",
"Microsoft.Extensions.Logging.Console": "1.0.0",
"Microsoft.Extensions.Logging.Debug": "1.0.0",
"Microsoft.Extensions.Options.ConfigurationExtensions": "1.0.0",
"Microsoft.VisualStudio.Web.BrowserLink.Loader": "14.0.0"
},

"tools": {
"BundlerMinifier.Core": "2.0.238",
"Microsoft.AspNetCore.Razor.Tools": "1.0.0-preview2-final",
"Microsoft.AspNetCore.Server.IISIntegration.Tools": "1.0.0-preview2-final"
},

"frameworks": {
"net452": {
"dependencies": {
"DataAccess": {
"target": "project"
},
"Models": {
"target": "project"
}
}
}
},

"buildOptions": {
"emitEntryPoint": true,
"preserveCompilationContext": true
},

"publishOptions": {
"include": [
"wwwroot",
"Views",
"Areas/**/Views",
"appsettings.json",
"web.config"
]
},
"runtimes": {
"win10-x64": {},
"osx.10.11-64": {}
},
"scripts": {
"prepublish": [ "bower install", "dotnet bundle" ],
"postpublish": [ "dotnet publish-iis --publish-folder %publish:OutputPath% --framework %publish:FullTargetFramework%" ]
}
}

从 startup.cs 配置

public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
Mapper.Initialize(config =>
{
/*View Models*/
config.CreateMap<Permit, PermitViewModel>().ReverseMap();
config.CreateMap<PermitType, PermitTypeViewModel>().ReverseMap();
config.CreateMap<Property, PropertyViewModel>().ReverseMap();
config.CreateMap<Region, RegionViewModel>().ReverseMap();
config.CreateMap<State, StateViewModel>().ReverseMap();
config.CreateMap<User, UserViewModel>().ReverseMap();

/*Dtos*/
config.CreateMap<Permit, PermitDto>().ReverseMap();
config.CreateMap<Property, PropertyDto>().ReverseMap();
config.CreateMap<Region, RegionDto>().ReverseMap();
config.CreateMap<State, StateDto>().ReverseMap();
config.CreateMap<User, UserDto>().ReverseMap();
});

loggerFactory.AddConsole(Configuration.GetSection("Logging"));
loggerFactory.AddDebug();

app.UseApplicationInsightsRequestTelemetry();

if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
app.UseBrowserLink();
}
else
{
app.UseExceptionHandler("/Home/Error");
}

app.UseApplicationInsightsExceptionTelemetry();

app.UseStaticFiles();

app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller=Home}/{action=Index}/{id?}");
});
}
}

program.cs

public static void Main(string[] args)
{
var host = new WebHostBuilder()
.UseKestrel()
.UseContentRoot(Directory.GetCurrentDirectory())
.UseIISIntegration()
.UseStartup<Startup>()
.Build();

host.Run();
}

我的目标是让它在 iis 上运行。

更新

Software: Microsoft Internet Information Services 8.5

Version: 1.0

Date: 2016-12-06 23:49:44

Fields: date time s-ip cs-method cs-uri-stem cs-uri-query s-port cs-username c-ip cs(User-Agent) cs(Referer) sc-status sc-substatus

sc-win32-status time-taken 2016-12-06 23:49:44 fe80::9c6d:a91b:42c:82ea%12 OPTIONS / - 80 - fe80::c510:a062:136b:abe9%12 DavClnt - 200 0 0 1139 2016-12-06 23:49:47 fe80::9c6d:a91b:42c:82ea%12 OPTIONS /website - 80 - fe80::c510:a062:136b:abe9%12 Microsoft-WebDAV-MiniRedir/10.0.14393 - 200 0 0 46 2016-12-06 23:49:47 fe80::9c6d:a91b:42c:82ea%12 PROPFIND /website - 80 - fe80::c510:a062:136b:abe9%12 Microsoft-WebDAV-MiniRedir/10.0.14393 - 404 0 2 62 2016-12-06 23:49:47 fe80::9c6d:a91b:42c:82ea%12 PROPFIND /website - 80 - fe80::c510:a062:136b:abe9%12 Microsoft-WebDAV-MiniRedir/10.0.14393 - 404 0 2 62

这是我得到的日志信息

web.config

<?xml version="1.0" encoding="utf-8"?>
<configuration>

<!--
Configure your application settings in appsettings.json. Learn more at http://go.microsoft.com/fwlink/?LinkId=786380
-->

<system.webServer>
<handlers>
<add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModule" resourceType="Unspecified"/>
</handlers>
<aspNetCore processPath="%LAUNCHER_PATH%" arguments="%LAUNCHER_ARGS%" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" forwardWindowsAuthToken="false"/>
</system.webServer>
</configuration>

最佳答案

请检查平台部分的"platform": "anycpu":

"Microsoft.NETCore.App": {
"version": "1.0.0",
"type": "platform"
},

 "buildOptions": {
"platform": "anycpu",
"emitEntryPoint": true,
"preserveCompilationContext": true
},

关于c# - Asp.net 核心部署不能在服务器上运行,但可以在机器上运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40812787/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com