Created
April 6, 2016 15:16
-
-
Save bbehrens/b1996bc012de5000e654e411fc3a3e86 to your computer and use it in GitHub Desktop.
This file contains 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 System; | |
using System.IO; | |
using Microsoft.AspNetCore.Builder; | |
using Microsoft.AspNetCore.Hosting; | |
using Microsoft.Extensions.Configuration; | |
using Microsoft.Extensions.DependencyInjection; | |
using Microsoft.Extensions.Logging; | |
using Newtonsoft.Json.Serialization; | |
namespace SelfService | |
{ | |
public class Startup | |
{ | |
string _contentRootPath; | |
public const string SELF_SERVICE_AUTHENTICATION_SCHEME = "SelfServiceCookieMiddlewareAuthScheme"; | |
public Startup(IHostingEnvironment hostingEnvironment) | |
{ | |
_contentRootPath = hostingEnvironment.ContentRootPath; | |
var builder = new ConfigurationBuilder() | |
.AddJsonFile($"{Path.Combine(_contentRootPath, "Options/dynamoDbOptions.json")}") | |
.AddEnvironmentVariables(); | |
builder.Build(); | |
} | |
// 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 IServiceProvider ConfigureServices(IServiceCollection services) | |
{ | |
services.AddMvc() | |
.AddJsonOptions(opts => opts.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver()) | |
.AddControllersAsServices(); | |
#if DNX451 | |
services.AddMvcDnx(); | |
#endif | |
services.AddAuthentication(options => options.SignInScheme = SELF_SERVICE_AUTHENTICATION_SCHEME); | |
return services.BuildServiceProvider(); | |
} | |
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. | |
public void Configure1(IApplicationBuilder app, IHostingEnvironment hostingEnvironment, ILoggerFactory loggerFactory) | |
{ | |
loggerFactory.AddConsole(); | |
app.UseIISPlatformHandler(); | |
app.UseDeveloperExceptionPage(); | |
app.UseStaticFiles(); | |
app.UseCookieAuthentication( | |
new CookieAuthenticationOptions | |
{ | |
AuthenticationScheme = SELF_SERVICE_AUTHENTICATION_SCHEME, | |
AutomaticAuthenticate = true, | |
} | |
); | |
app.UseMvc(); | |
} | |
// Entry point for the application. | |
public static void Main(string[] args) | |
{ | |
var host = new WebHostBuilder() | |
.UseDefaultHostingConfiguration(args) | |
.UseIISPlatformHandlerUrl() | |
.UseServer("Microsoft.AspNetCore.Server.Kestrel") | |
.UseStartup<Startup>() | |
.Build(); | |
host.Run(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment