Exemplo n.º 1
0
        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();

            WebApiConfig.Register(GlobalConfiguration.Configuration);
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            //BundleConfig.RegisterBundles(BundleTable.Bundles);

            BootstrapConfig.RegisterBundles(BundleTable.Bundles);

            _container = new WindsorContainer();

            _container.Install(new ControllersInstaller());

            ControllerBuilder.Current.SetControllerFactory(
                new WindsorControllerFactory(_container.Kernel));

            Members = new Dictionary <string, User>();
            var chavp = new User
            {
                Name     = "#:P",
                Email    = "*****@*****.**",
                Password = "******".GetHashCode().ToString(),
            };

            Members.Add(chavp.Name, chavp);
            UserRoleDic = new Dictionary <string, string[]>();

            UserRoleDic.Add(chavp.Name, new string[] { "admin" });
        }
 /// <summary>
 /// 注册映射
 /// </summary>
 /// <param name="config"></param>
 private void RegistAutoMapper(BootstrapConfig config)
 {
     config.AutoMapperConfigurator = (cfg =>
     {
         cfg.CreateMap(typeof(CompanyFullInfoRequest), typeof(Company), false);
         cfg.CreateMap(typeof(CompanyFullInfoRequest), typeof(CompanyConnectRecord), false);
     });
 }
        public void Configuration(IAppBuilder app)
        {
            log4net.Config.XmlConfigurator.Configure();
            ILog logger = LogManager.GetLogger("Logger");

            logger.Info("Application Started");
            logger.Info("Configuring DI container");
            IWindsorContainer container = new WindsorContainer();

            ServiceLocator.Set(container);
            BootstrapConfig.Register(container, logger);

            logger.Info("Configuring HTTP Middleware");
            app.MapSignalR();
            app.UseMultitenancy(new MultitenancyNotifications <TenantDto>
            {
                TenantIdentifierNotFound = context =>
                {
                    throw new HttpException(404, "Tenant identifier must be provided");
                },
                TenantRecordNotFound = context =>
                {
                    context.Response.Redirect("/signup/tenant/");
                    return(Task.FromResult(0));
                },
                CreateTenantContext = (context, tenantRecord) =>
                {
                    ITenantContextFactory tenantContextFactory = ServiceLocator.Resolve <ITenantContextFactory>();
                    TenantContext tenantContext = tenantContextFactory.Create(tenantRecord.Id, tenantRecord.NameFriendly, tenantRecord.AuthClientId, tenantRecord.AuthAuthority);
                    return(Task.FromResult(tenantContext));
                }
            });
            app.UsePerTenant((tenantContext, appBranch) =>
            {
                appBranch.SetDefaultSignInAsAuthenticationType(CookieAuthenticationDefaults.AuthenticationType);

                appBranch.UseCookieAuthentication(new CookieAuthenticationOptions
                {
                    CookieName = $"OAuthCookie.{tenantContext.FriendlyName}"
                });

                appBranch.UseOpenIdConnectAuthentication(new OpenIdConnectAuthenticationOptions
                {
                    ClientId      = tenantContext.AuthClientId,
                    Authority     = tenantContext.AuthAuthority,
                    RedirectUri   = $"http://localhost:2295/{tenantContext.FriendlyName}/",
                    Notifications = new OpenIdConnectAuthenticationNotifications()
                    {
                        AuthenticationFailed = context =>
                        {
                            context.HandleResponse();
                            throw context.Exception;
                        }
                    }
                });

                appBranch.Use <AuthenticationChallangeMiddleware>();
                appBranch.Use <AuthenticationAudienceCheckMiddleware>(tenantContext);
                appBranch.Use <AuthenticationClaimsAppenderMiddleware>();
            });

            logger.Info("Configuring MVC Pipeline");
            AreaRegistration.RegisterAllAreas();
            WebApiConfig.Register(GlobalConfiguration.Configuration);
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);
            AntiForgeryConfig.UniqueClaimTypeIdentifier = ClaimTypes.NameIdentifier;

            logger.Info("Configuring Domain, DTO and Model Mapping");
            MappingConfig.RegisterMapping();
            Mapper.AddProfile(new Web.Models.Map());

            app.OnDispose(() =>
            {
                ServiceLocator.Resolve <ILog>().Info("Application Ended");
                ServiceLocator.Release();
            });
        }