自包含的asp核心1不起作用

时间:2016-09-30 11:15:23

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

我尝试制作一个' exe'对于我的WebCoreApplication,在发布命令后,dotnet发布-c release -r win10-x64' ,我有一个文件夹和.exe。当我运行这个exe时,它用我的应用程序打开一个端口localhost:5000,但是没有显示任何内容......

这是我的package.json



{
  "version": "1.0.0-*",
  "buildOptions": {
    "emitEntryPoint": true,
    "preserveCompilationContext": true

  },

  "dependencies": {
    "Microsoft.NETCore.App": "1.0.0",
    "Microsoft.EntityFrameworkCore.SqlServer": "1.0.1",
    "Microsoft.EntityFrameworkCore.Design": "1.0.0-preview2-final",
    "Microsoft.AspNetCore.Mvc": "1.0.0",
    "System.Linq": "4.1.0",
    "System.Linq.Parallel": "4.0.1",
    "Microsoft.AspNetCore.Mvc.TagHelpers": "1.0.1",
    "Microsoft.AspNetCore.Identity.EntityFrameworkCore": "1.0.0",
    "Microsoft.AspNetCore.Identity": "1.0.0",
    "Portable.BouncyCastle": "1.8.1.1",
    "Microsoft.AspNetCore.Hosting": "1.0.0",
    "Microsoft.AspNetCore.Server.Kestrel": "1.0.1",
    "System.IO.FileSystem": "4.0.1",
    "Microsoft.AspNetCore.Server.IISIntegration": "1.0.0",
    "Microsoft.Extensions.Configuration.FileExtensions": "1.0.0",
    "Microsoft.AspNetCore.StaticFiles": "1.0.0",
    "Microsoft.Extensions.Configuration.Json": "1.0.0",
    "Microsoft.EntityFrameworkCore": "1.0.1",
    "Microsoft.Extensions.DependencyInjection": "1.0.0",
    "Microsoft.Extensions.DependencyInjection.Abstractions": "1.0.0",
    "Microsoft.Extensions.Logging": "1.0.0",
    "Microsoft.Extensions.Logging.Console": "1.0.0",
    "Microsoft.Extensions.Logging.Debug": "1.0.0"
  },

  "frameworks": {
    "netcoreapp1.0": {}
  },

  "runtimeOptions": {
    "configProperties": {
      "System.GC.Server": true
    }
  },

  "runtimes": {
    "win10-x64": { },
    "win10-x86": { },
    "win81-x64": { },
    "win81-x86": { },
    "win7-x64": { },
    "win7-x86": { }
  },

  "publishOptions": {
    "include": [
      "wwwroot",
      "web.config",
      "config.json",
      "**.user",
       "**.vspscc"
    ]
  }
}




这里是我的startup.cs

    using Microsoft.AspNetCore.Authentication.Cookies;
using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Newtonsoft.Json.Serialization;
using System.Net;
using System.Threading.Tasks;
using TraficC.Model;
using TraficC.Model.Services;
using System.IO;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;

namespace TraficC
{
    public class Startup
    {
        public static IConfigurationRoot Configuration;

        public Startup(IHostingEnvironment appEnv)
        {
            var builder = new ConfigurationBuilder()
            .SetBasePath(appEnv.ContentRootPath)
            .AddJsonFile("config.json")
            .AddEnvironmentVariables();
            Configuration = builder.Build();
        }

        public void ConfigureServices(IServiceCollection services)
        {
            services.AddMvc()
                .AddJsonOptions(opt =>
                {
                    opt.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver();
                });

            services.AddIdentity<PeopleUser, IdentityRole>(config =>
             {
                 config.User.RequireUniqueEmail = true;
                 config.Password.RequiredLength = 8;
                 config.Cookies.ApplicationCookie.LoginPath = "/Home/login";
                 config.Cookies.ApplicationCookie.Events = new CookieAuthenticationEvents()
                 {
                     OnRedirectToLogin = ctx =>
                     {
                         if (ctx.Request.Path.StartsWithSegments("/api") && ctx.Response.StatusCode == (int)HttpStatusCode.OK)
                         {
                             ctx.Response.StatusCode = (int)HttpStatusCode.Unauthorized;
                         }

                         ctx.Response.Redirect(ctx.RedirectUri);
                         return Task.FromResult(0);
                     }
                 };
             })
                 .AddEntityFrameworkStores<DataMasterSpringfieldDbContext>()
                 .AddDefaultTokenProviders();
            services.AddEntityFrameworkSqlServer()
                .AddDbContext<DataMasterSpringfieldDbContext>();

            services.AddTransient<DataMasterSpringfieldDbContextSeedData>();
            services.AddScoped<IPeopleRepository, PeopleRepository>();
            services.AddScoped<IMailService, MailService>();
        }

        public async void Configure(IApplicationBuilder app, DataMasterSpringfieldDbContextSeedData seeder)
        {
            app.UseStaticFiles();
            app.UseIdentity();
            app.UseMvc(config =>
            {
                config.MapRoute(

                  name: "Default",
                  template: "{controller}/{action}/{id?}",
                  defaults: new { controller = "Home", action = "login" }
                  );
            });
            await seeder.EnsureSeedDataAsync();

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

               host.Run();
           }
       }
   }

0 个答案:

没有答案