Exemplo n.º 1
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
        {
            loggerFactory.AddConsole(Configuration.GetSection("Logging"));
            loggerFactory.AddFile(Configuration.GetSection("Logging"));

            if (!HostingEnvironment.IsEnvironment("test"))
            {
                app.UseJwtBearerAuthentication(Jwt.GetJwtOptions());
            }

            app.UseCors(p =>
            {
                p.WithOrigins("");
            });
            //todo:实际项目中,放在登录授权里面
            app.Map("/auth/test", appbuilder =>
            {
                appbuilder.Run(d =>
                {
                    var token = Jwt.SignToken(new List <Claim>()
                    {
                        new Claim("name", "ryan")
                    });

                    return(d.Response.WriteAsync(token));
                });
            });

            app.UseMvc(routes =>
            {
                routes.MapRoute(
                    "default",
                    "api/{controller=Values}/{action=Hello}/{id?}");
            });
            if (HostingEnvironment.IsDevelopment())
            {
                loggerFactory.AddDebug();
                app.UseSwagger();
                app.UseSwaggerUi(c => c.SwaggerEndpoint("/swagger/v1/swagger.json", "V1 Docs"));
            }
            // appLifetime?.ApplicationStopped.Register(() => this.Container.Dispose());
        }