Пример #1
0
        public static void RegisterRoutes(HttpConfiguration config, ConfigProfile cp)
        {
            //κάνει enable το attribute routing
            config.MapHttpAttributeRoutes();

            // CSRF tokens in GET requests are potentially leaked at several locations:
            // browser history, HTTP log files, network appliances that make a point to
            // log the first line of an HTTP request, and Referrer headers if the protected
            // site links to an external site. This is why we don't add the /{token} in route.
            config.Routes.MapHttpRoute(
                name: CONTROLLER_ACTION,
                routeTemplate: "{controller}/{action}",
                defaults: null//new { token = ""}
                );

            Container container = new Container();

            container.Options.DefaultScopedLifestyle = new SimpleInjector.Lifestyles.AsyncScopedLifestyle();

            container.Register <Func <PersistentLib.ISqlFactory> >(() => () => new PersistentLib.SqlServerFactory(cp.TokenCacheConnection));
            container.Register <Func <JsonSerializerSettings> >(() => () => GetSerializationSettings());
            container.Register <DistributedSessionSecurityTokenCache.RollingExpirationProvider>(() => () => cp.RollingExpiryWindowInMinutes);

            container.Register <IDistributedSessionSecurityTokenCache, DistributedSessionSecurityTokenCache>();
            container.Register <IDistributedTokenReplayCache, DistributedTokenReplayCache>();

            container.RegisterWebApiControllers(GlobalConfiguration.Configuration);

            container.Verify();
            GlobalConfiguration.Configuration.DependencyResolver = new SimpleInjectorWebApiDependencyResolver(container);
        }
Пример #2
0
        private static void RegisterHandlers(
            System.Collections.ObjectModel.Collection <System.Net.Http.DelegatingHandler> handlers,
            ConfigProfile cp)
        {
            //handlers.Add(new bUtility.Handlers.AuthenticationHandler());

            //handlers.Add(new bUtility.Handlers.ThrottlingHandler(999, 0));
        }
Пример #3
0
 private static void RegisterLocalServices(ConfigProfile cp)
 {
     try
     {
         throw new ApplicationException($"test Exception @ {appName}");
     }
     catch (Exception ex)
     {
         Logger.Current.Error(ex);
     }
 }
Пример #4
0
        protected void Application_Start()
        {
            Logger.SetCurrent(new Logger("tokenCacheSource"));


            // Remove Header X-AspNetMvc-Version
            //MvcHandler.DisableMvcResponseHeader = true;
            //AreaRegistration.RegisterAllAreas();
            var cp = ConfigProfile.LoadConfigurationProfile();

            WebApiConfig.Configure(cp);
        }
Пример #5
0
        internal static ConfigProfile LoadConfigurationProfile()
        {
            var cp = new ConfigProfile
            {
                TokenCacheConnection = ConfigurationManager.AppSettings["tokenCacheConnection"],
                RequireHttps         = LoadBooleanValue("RequireHttps"),

                RollingExpiryWindowInMinutes = LoadIntValue("rollingExpiringWindowInMinutes", 65),
            };

            Current = cp;
            return(cp);
        }
Пример #6
0
 public static void RegisterGlobalFilters(HttpFilterCollection filters, ConfigProfile cp)
 {
     filters.Add(new ExceptionHandlingAttribute());
     //filters.Add(new NoCacheAttribute());
     //if (cp.RequireHttps)
     //{
     //    // Require https only connection
     //    filters.Add(new RequireHttpsAttribute());
     //}
     //else
     //{
     //    Logger.Current.Warn( $"Require HTTPS is disabled for {appName}");
     //}
 }
Пример #7
0
 public static void Configure(ConfigProfile cp)
 {
     try
     {
         GlobalConfiguration.Configure((httpConf) =>
         {
             RegisterRoutes(httpConf, cp);
             RegisterGlobalFilters(httpConf.Filters, cp);
             //CustomizeFormatters(httpConf.Formatters);
             //RegisterHandlers(httpConf.MessageHandlers, cp);
             RegisterLocalServices(cp);
         });
     }
     catch (Exception ex)
     {
         Logger.Current.Error(ex);
     }
 }