-
Notifications
You must be signed in to change notification settings - Fork 0
/
Startup.cs
107 lines (91 loc) · 4.37 KB
/
Startup.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Microsoft.EntityFrameworkCore;
using InternalPortal.Models;
using InternalPortal.Models.Helpers;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Authentication.JwtBearer;
using System.IdentityModel.Tokens;
using Microsoft.IdentityModel.Tokens;
using System.Text;
namespace InternalPortal
{
public class Startup
{
public Startup(IHostingEnvironment env)
{
var builder = new ConfigurationBuilder()
.SetBasePath(env.ContentRootPath)
.AddJsonFile("appsettings.json", optional: false, reloadOnChange: true)
.AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true)
.AddEnvironmentVariables();
Configuration = builder.Build();
//GlobalConfiguration.Configuration.Formatters.JsonFormatter.SerializerSettings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore;
}
public IConfigurationRoot Configuration { get; }
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
// Add CORS support
services.AddCors(options =>
{
options.AddPolicy("CorsPolicy",
builder => builder.AllowAnyOrigin()
.AllowAnyMethod()
.AllowAnyHeader()
.AllowCredentials());
});
// Add framework services.
services.AddMvc()
.AddJsonOptions(options => {
options.SerializerSettings.ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore;
});
services.AddDbContext<GcimsContext>(options =>
options.UseSqlServer(Configuration.GetConnectionString("GcimsContext")));
// services.AddDbContext<PortalContext>(options =>
// options.UseSqlServer(Configuration.GetConnectionString("PortalContext")));
services.AddDbContext<PortalContext>(options =>
options.UseSqlServer(Configuration.GetConnectionString("PortalContext2")));
// services.AddDbContext<PortalContext>(options =>
// options.UseNpgsql(Configuration.GetConnectionString("PortalContextPsql")));
// services.AddAuthorization(options =>
// {
// options.AddPolicy(
// "InternalUser",
// policy => policy.Requirements.Add(new InternalUserRequirement()));
// });
// services.AddSingleton<IAuthorizationHandler, InternalUserHandler>();
// services.Configure<IISOptions>(options => options.ForwardWindowsAuthentication = true);
// services.AddMvc();
//services.Configure<IISOptions>(options => options.AutomaticAuthentication = true);
}
// 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.AddDebug();
// app.UseJwtBearerAuthentication(new JwtBearerOptions
// {
// AutomaticAuthenticate = true,
// AutomaticChallenge = true,
// TokenValidationParameters = new TokenValidationParameters
// {
// IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(Configuration.GetSection("AppConfiguration:Key").Value)),
// ValidAudience = Configuration.GetSection("AppConfiguration:SiteUrl").Value,
// ValidateIssuerSigningKey = true,
// ValidateLifetime = true,
// ValidIssuer = Configuration.GetSection("AppConfiguration:SiteUrl").Value
// }
// });
app.UseCors("CorsPolicy");
app.UseMvc();
}
}
}