Asp.net核心部署无法在服务器上运行,但适用于计算机

时间:2016-11-25 22:07:10

标签: c# .net iis deployment asp.net-core

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

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

  1. 构建VM
  2. 更新所有ms更新
  3. 添加iis角色
  4. 确保在机器上安装asp.net 3.5和4.5
  5. 确保安装http重定向和静态内容
  6. 安装.net核心软件包
  7. 从Visual Studio发布自包含应用程序(项目名称Web)
  8. 将其添加到服务器上的文件夹中。
  9. 尝试从web.exe运行
  10. 我打开控制台应用程序说现在正在听取:http://localhost:5000 10.我从这台机器上的chrome转到http://localhost:5000并找不到404。

    我在本地机器上执行步骤7 8 9和10,这是Windows 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上运行。

    更新

      

    软件:Microsoft Internet Information Services 8.5

         

    版本:1.0

         

    日期:2016-12-06 23:49:44

         

    字段:日期时间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拍摄时间2016-12-06 23:49:44   fe80 :: 9c6d:a91b:42c:82ea%12选项/ - 80 -   fe80 :: c510:a062:136b:abe9%12 DavClnt - 200 0 0 1139 2016-12-06   23:49:47 fe80 :: 9c6d:a91b:42c:82ea%12选项/网站 - 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>
    

3 个答案:

答案 0 :(得分:3)

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

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

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

答案 1 :(得分:2)

这是一个真正受益于更多文档的问题。这就是我这样做的方式,我并不是说这是唯一的方法。

1.确保已安装dotnetcore主机

2.创建一个针对&#34;没有托管代码的应用池&#34;

3.创建使用该应用程序池的网站(这是您定义IIS将侦听的IP地址和端口的位置)

4.发布Web部署包(Visual Studio)(它将为您提供一个zip文件夹)

5.将该zip文件夹移动到服务器

6.转到您创建的网站并右键单击该网站(确保网站已停止)

7.我无法记住确切的选项,但它可以实现&#34;管理网站&#34;您应该获得另一个菜单,为您提供导入选项

8.单击它并浏览该zip文件夹您可以设置其他选项

9.完成后再次启动网站

10.然后,您应该能够使用为IIS中的网站配置的IP地址在浏览器中转到您的应用程序

答案 2 :(得分:0)

如果我没有误会,你的project.json没有引用asp.NET-core,而是参考完整的框架:

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

我认为你错过了某个目标.NETCore:)

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