示例#1
0
        protected override void ApplicationStartup(ILifetimeScope container, IPipelines pipelines)
        {
            StaticConfiguration.DisableErrorTraces = false;

            // Enable memory sessions, and secure them against session hijacking
            pipelines.EnableInProcSessions();

            /*pipelines.BeforeRequest.AddItemToStartOfPipeline(ctx => {
             * var antiSessionHijackLogic = container.Resolve<IAntiSessionHijackLogic>();
             * return antiSessionHijackLogic.InterceptHijackedSession(ctx.Request);
             * });
             * pipelines.AfterRequest.AddItemToEndOfPipeline(ctx => {
             * var antiSessionHijackLogic = container.Resolve<IAntiSessionHijackLogic>();
             * antiSessionHijackLogic.ProtectResponseFromSessionHijacking(ctx);
             * });*/

            // Load the user from the AspNet session. If one is found, create a Nancy identity and assign it.
            pipelines.BeforeRequest.AddItemToEndOfPipeline(ctx => {
                var identityAssigner = container.Resolve <INancyIdentityFromContextAssigner>();
                identityAssigner.AssignNancyIdentityFromContext(ctx);
                return(null);
            });

            // Auto return response when one of the known exceptions is thrown
            pipelines.OnError = pipelines.OnError
                                + ErrorPipelines.HandleModelBindingException()
                                + ErrorPipelines.HandleRequestValidationException()
                                + ErrorPipelines.HandleSecurityException();

            base.ApplicationStartup(container, pipelines);
        }
示例#2
0
        public AppBootstrapper(Action <ConfigurableBootstrapperConfigurator> configuration, bool enableViewSupportWhichMakesTheUnitTestsReallySlow = false) : base(with => {
            if (enableViewSupportWhichMakesTheUnitTestsReallySlow)
            {
                // Do not use view support if it is not needed. Makes the unit tests much slower.
                with.ViewLocationProvider <FileSystemViewLocationProvider>();
                with.ViewFactory <TestingViewFactory>();
            }
            configuration(with);
        }) {
            JsonSerializer = new CustomJsonSerializer();
            InternalConfiguration.Serializers.Clear();
            InternalConfiguration.Serializers.Add(JsonSerializer.GetType());

            BeforeRequest.AddItemToEndOfPipeline(context => {
                if (AuthenticatedUser == null)
                {
                    context.CurrentUser = null;
                }
                else
                {
                    var userIdentity    = new VoterIdentity(AuthenticatedUser);
                    context.CurrentUser = userIdentity;
                }
                return(null);
            });

            OnError = OnError
                      + ErrorPipelines.HandleModelBindingException()
                      + ErrorPipelines.HandleRequestValidationException()
                      + ErrorPipelines.HandleSecurityException();
        }
 public void SetUp()
 {
     _sut = ErrorPipelines.HandleRequestValidationException();
 }