Created
July 4, 2016 16:32
-
-
Save orlaqp/f8ab1c9dfb374ea0e839d10cf5f7f4a6 to your computer and use it in GitHub Desktop.
Startup for my first ASP .NET Core 1.0
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Microsoft.AspNetCore.Builder; | |
using Microsoft.AspNetCore.Hosting; | |
using Microsoft.AspNetCore.Http; | |
using Microsoft.AspNetCore.Identity.EntityFrameworkCore; | |
using Microsoft.EntityFrameworkCore; | |
using Microsoft.Extensions.Configuration; | |
using Microsoft.Extensions.DependencyInjection; | |
using Microsoft.Extensions.Logging; | |
using Security.Models; | |
using OpenIddict; | |
namespace Security | |
{ | |
public class Startup | |
{ | |
public Startup(IHostingEnvironment env) | |
{ | |
var builder = new ConfigurationBuilder() | |
.AddJsonFile("appsettings.json"); | |
//.AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true); | |
//if (env.IsDevelopment()) | |
//{ | |
// builder.AddUserSecrets(); | |
//} | |
builder.AddEnvironmentVariables(); | |
Configuration = builder.Build(); | |
} | |
public IConfiguration Configuration { get; set; } | |
// This method gets called by the runtime. Use this method to add services to the container. | |
// For more information on how to configure your application, visit http://go.microsoft.com/fwlink/?LinkID=398940 | |
public void ConfigureServices(IServiceCollection services) | |
{ | |
services.AddSingleton(provider => Configuration); | |
services.AddCors(); | |
services.AddDbContext<ApplicationDbContext>(options => | |
options.UseSqlServer(Configuration["Data:DefaultConnection:ConnectionString"])); | |
services.AddIdentity<ApplicationUser, IdentityRole>() | |
.AddEntityFrameworkStores<ApplicationDbContext>() | |
.AddDefaultTokenProviders(); | |
services.AddOpenIddict<ApplicationUser, ApplicationDbContext>() | |
.DisableHttpsRequirement(); | |
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, ILoggerFactory loggerFactory) | |
{ | |
loggerFactory.AddConsole(); | |
loggerFactory.AddDebug(); | |
app.UseCors(builder => | |
builder.AllowAnyHeader() | |
.AllowAnyMethod() | |
.AllowAnyOrigin() | |
); | |
if (env.IsDevelopment()) | |
{ | |
app.UseDeveloperExceptionPage(); | |
app.UseDatabaseErrorPage(); | |
} | |
app.UseFileServer(); | |
app.UseIdentity(); | |
app.UseOpenIddict(); | |
app.UseMvcWithDefaultRoute(); | |
//app.Run(async (context) => | |
//{ | |
// await context.Response.WriteAsync("Hello World!"); | |
//}); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment