public static void ContextSetup(this IServiceCollection services, IConfiguration Configuration)
 {
     DBConnectionContext.getconnection(Configuration);
     MapProxy.webProxyURI      = Configuration["webProxy:URL"];
     MapProxy.webProxyUsername = Configuration["webProxy:Username"];
     MapProxy.webProxyPassword = Configuration["webProxy:Password"];
     MapProxy.WebProxyEnable   = Configuration["webProxy:Enable"];
 }
Пример #2
0
        // 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 https://go.microsoft.com/fwlink/?LinkID=398940
        public void ConfigureServices(IServiceCollection services)
        {
            // ********************
            // Setup CORS
            // ********************
            services.AddCors(c =>
            {
                c.AddPolicy("AllowAtUIOrigin", options => options.WithOrigins(Configuration["CorsEnableDomain:Domain"]));
            });

            DBConnectionContext.getconnection(Configuration);
            MapProxy.webProxyURI      = Configuration["webProxy:URL"];
            MapProxy.webProxyUsername = Configuration["webProxy:Username"];
            MapProxy.webProxyPassword = Configuration["webProxy:Password"];
            MapProxy.WebProxyEnable   = Configuration["webProxy:Enable"];

            services.AddSingleton <IQuincusAddressTranslationRequest>(new QuincusAddressTranslationRequest()
            {
                endpoint = Configuration["Quincus:GeoCodeEndPoint"]
            });
            services.AddMvc().SetCompatibilityVersion(Microsoft.AspNetCore.Mvc.CompatibilityVersion.Version_2_1);
            services.AddSingleton <IHttpContextAccessor, HttpContextAccessor>();

            services.AddDbContext <ApplicationDbContext>(
                option => option.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")));

            services.AddIdentity <IdentityUser, IdentityRole>(
                option =>
            {
                option.Password.RequireDigit           = false;
                option.Password.RequiredLength         = 6;
                option.Password.RequireNonAlphanumeric = false;
                option.Password.RequireUppercase       = false;
                option.Password.RequireLowercase       = false;
            }).AddEntityFrameworkStores <ApplicationDbContext>().AddDefaultTokenProviders();


            services.AddAuthentication(new AuthenticationOptions().DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme);
            services.AddAuthentication(new AuthenticationOptions().DefaultChallengeScheme    = JwtBearerDefaults.AuthenticationScheme);
            services.AddAuthentication(new AuthenticationOptions().DefaultScheme             = JwtBearerDefaults.AuthenticationScheme);

            services.AddAuthentication().AddJwtBearer(options =>
            {
                options.SaveToken                 = true;
                options.RequireHttpsMetadata      = true;
                options.TokenValidationParameters = new Microsoft.IdentityModel.Tokens.TokenValidationParameters()
                {
                    ValidateIssuer   = true,
                    ValidateAudience = true,
                    ValidAudience    = Configuration["Jwt:Site"],
                    ValidIssuer      = Configuration["Jwt:Site"],
                    IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes("Pactera IDC JWT Integration"))
                };
            });

            Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
        }
Пример #3
0
        public ActionResult Index()
        {
            var db       = new DBConnectionContext();
            var employee = new Employee
            {
                ID        = Guid.NewGuid(),
                FirstName = "Sam",
                LastName  = "Blah",
                Address   = "Pyrmont"
            };

            db.Employees.Add(employee);
            db.SaveChanges();

            var test = db.Employees.ToList();

            return(View(test));
        }