当前位置: 首页>>代码示例>>C#>>正文


C# IPipelines类代码示例

本文整理汇总了C#中IPipelines的典型用法代码示例。如果您正苦于以下问题:C# IPipelines类的具体用法?C# IPipelines怎么用?C# IPipelines使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


IPipelines类属于命名空间,在下文中一共展示了IPipelines类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: RequestStartup

        protected override void RequestStartup(TinyIoCContainer container, IPipelines pipelines, NancyContext context)
        {
            var formsAuthConfiguration =
                new FormsAuthenticationConfiguration()
                {
                    RedirectUrl = "~/login",
                    UserMapper = container.Resolve<IUserMapper>(),
                };

            FormsAuthentication.Enable(pipelines, formsAuthConfiguration);
            CookieBasedSessions.Enable(pipelines);

            pipelines.BeforeRequest.AddItemToStartOfPipeline(ctx =>
                {
                    if (Helper.Settings.Instance.Client.CanConnect)
                        return null;
                    else
                    {
                        if (String.Compare(ctx.Request.Path, "/notavailable", true) == 0)
                        {
                            return null;
                        }
                        return new RedirectResponse("/notavailable");
                    }
                });

            base.RequestStartup(container, pipelines, context);
        }
开发者ID:ChrisK91,项目名称:CWSRestart,代码行数:28,代码来源:ApplicationBootstrapper.cs

示例2: Initialize

    public void Initialize(IPipelines pipelines)
    { 
      pipelines.BeforeRequest.AddItemToStartOfPipeline(RunCassetteHandler);
      pipelines.BeforeRequest.AddItemToStartOfPipeline(InitializeCassetteRequestState);

      pipelines.AfterRequest.AddItemToEndOfPipeline(RewriteResponseContents);
    }
开发者ID:thefringeninja,项目名称:Cassette.Nancy,代码行数:7,代码来源:CassetteStartup.cs

示例3: ApplicationStartup

        protected override void ApplicationStartup(TinyIoCContainer container, IPipelines pipelines)
        {
            base.ApplicationStartup(container, pipelines);

            // In reality you would use a pre-built authentication/claims provider
            pipelines.BeforeRequest += (ctx) =>
            {
                // World's-worse-authentication (TM)
                // Pull the username out of the querystring if it exists
                // and build claims from it
                var username = ctx.Request.Query.username;

                if (username.HasValue)
                {
                    ctx.CurrentUser = new DemoUserIdentity
                                          {
                                              UserName = username.ToString(),
                                              Claims = BuildClaims(username.ToString())
                                          };
                }

                return null;
            };

            pipelines.AfterRequest += (ctx) =>
            {
                // If status code comes back as Unauthorized then
                // forward the user to the login page
                if (ctx.Response.StatusCode == HttpStatusCode.Unauthorized)
                {
                    ctx.Response = new RedirectResponse("/login?returnUrl=" + Uri.EscapeDataString(ctx.Request.Path));
                }
            };
        }
开发者ID:Borzoo,项目名称:Nancy,代码行数:34,代码来源:AuthenticationBootstrapper.cs

示例4: RequestStartup

        protected override void RequestStartup(TinyIoCContainer container, IPipelines pipelines, NancyContext context)
        {
            var formsAuthConfig = new FormsAuthenticationConfiguration
            {
                RedirectUrl = "~/login",
                UserMapper = container.Resolve<IUserMapper>()
            };

            FormsAuthentication.Enable(pipelines, formsAuthConfig);

            pipelines.AfterRequest += ctx =>
            {
                var dbContext = container.Resolve<SmartFlowContext>();
                dbContext.SaveChanges();
            };

            pipelines.OnError += (ctx, ex) =>
            {
                var logger = container.Resolve<TextFileLogger>();
                logger.Write("Error", Enums.LogLevel.ApplicationError, ex);
                return ErrorResponse.FromException(ex);
            };

            base.RequestStartup(container, pipelines, context);
        }
开发者ID:DeanMcgarrigle,项目名称:SmartFlow,代码行数:25,代码来源:Bootstrapper.cs

示例5: Initialize

        /// <summary>
        /// Perform any initialisation tasks
        /// </summary>
        /// <param name="pipelines">Application pipelines</param>
        /// <param name="context">The current context</param>
        public void Initialize(IPipelines pipelines, NancyContext context)
        {
            // On each request, store the NancyContext in the LogicalCallContext
            CallContext.LogicalSetData(NancyConfiguration.NancyContextDataSlot, context);

            var nancyConfiguration = NancyConfiguration.Settings;
            if (nancyConfiguration == null)
                return;

            var name = nancyConfiguration.PipelineName.Value;
            var sharpRaven = new PipelineItem(name, (nancyContext, exception) =>
            {
                if (nancyConfiguration.CaptureExceptionOnError.Value)
                {
                    var guid = this.ravenClient.CaptureException(exception);

                    if (guid != null)
                    {
                        context.Items.Add(NancyConfiguration.SentryEventGuidKey, guid);
                        exception.Data.Add(NancyConfiguration.SentryEventGuidKey, guid);
                    }
                }

                return null;
            });

            pipelines.OnError.AddItemToStartOfPipeline(sharpRaven);
        }
开发者ID:getsentry,项目名称:raven-csharp,代码行数:33,代码来源:SentryRequestStartup.cs

示例6: ApplicationStartup

        protected override void ApplicationStartup(TinyIoCContainer container, IPipelines pipelines)
        {

            base.ApplicationStartup(container, pipelines);

            var configuration = new BasicAuthenticationConfiguration(container.Resolve<IUserValidator>(), "test-realm");
            BasicAuthentication.Enable(pipelines,configuration);

            var stateless = new StatelessAuthenticationConfiguration(c =>
            {
                const string key = "X-Auth-Token";
                string token = null;

                if (c.Request.Headers.Authorization == null || !c.Request.Headers.Authorization.Any())
                {
                    _log.ErrorFormat("No request headers are present in the request {0}", c);
                    return null;
                }

                if (c.Request.Headers.FirstOrDefault(f => f.Key == key).Value == null ||
                    string.IsNullOrEmpty(c.Request.Headers.FirstOrDefault(f => f.Key == key).Value.First()))
                {
                    _log.ErrorFormat("No Key present in the request headers");
                    return null;
                }

                token = c.Request.Headers.FirstOrDefault(f => f.Key == key).Value.First();
                _log.InfoFormat("Token used {0}", token);

                var user = container.Resolve<IUserApiMapper>();
                return user.GetUserFromToken(token);

            });
            StatelessAuthentication.Enable(pipelines, stateless);
        }
开发者ID:rjonker1,项目名称:lightstone-data-platform,代码行数:35,代码来源:Bootstrapper.cs

示例7: ApplicationStartup

 protected override void ApplicationStartup(TinyIoC.TinyIoCContainer container, IPipelines pipelines)
 {
     FormsAuthentication.Enable(pipelines, new FormsAuthenticationConfiguration {
         RedirectUrl = "~/login",
         UserMapper = _mocks[typeof(IUserRepository)] as IUserRepository
     });
 }
开发者ID:bobbles31,项目名称:Ideastrike,代码行数:7,代码来源:IdeaStrikeTestBootStrapper.cs

示例8: ApplicationStartup

        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;
              });

              pipelines.OnError = pipelines.OnError
            + ErrorPipelines.HandleModelBindingException()
            + ErrorPipelines.HandleRequestValidationException()
            + ErrorPipelines.HandleSecurityException();

              base.ApplicationStartup(container, pipelines);
        }
开发者ID:DavidLievrouw,项目名称:InvoiceGen,代码行数:29,代码来源:Bootstrapper.cs

示例9: Enable

        /// <summary>
        /// Enables forms authentication for the application
        /// </summary>
        /// <param name="pipelines">Pipelines to add handlers to (usually "this")</param>
        /// <param name="configuration">Forms authentication configuration</param>
        public static void Enable(IPipelines pipelines, FormsAuthenticationConfiguration configuration)
        {
            if (pipelines == null)
            {
                throw new ArgumentNullException("pipelines");
            }

            if (configuration == null)
            {
                throw new ArgumentNullException("configuration");
            }

            if (!configuration.IsValid)
            {
                throw new ArgumentException("Configuration is invalid", "configuration");
            }

            currentConfiguration = configuration;

            pipelines.BeforeRequest.AddItemToStartOfPipeline(GetLoadAuthenticationHook(configuration));
            if (!configuration.DisableRedirect)
            {
                pipelines.AfterRequest.AddItemToEndOfPipeline(GetRedirectToLoginHook(configuration));
            }
        }
开发者ID:rahulchrty,项目名称:Nancy,代码行数:30,代码来源:FormsAuthentication.cs

示例10: ApplicationStartup

 // The bootstrapper enables you to reconfigure the composition of the framework,
 // by overriding the various methods and properties.
 // For more information https://github.com/NancyFx/Nancy/wiki/Bootstrapper
 protected override void ApplicationStartup(TinyIoCContainer container, IPipelines pipelines)
 {
     container.Register<IStorage, Storage>().AsSingleton();
     container.Register<CredentialsStorage>().AsSingleton();
     var serverScheduler = new ServerScheduler(container.Resolve<IStorage>());
     serverScheduler.Start();
 }
开发者ID:Stelmashenko-A,项目名称:CourseWork,代码行数:10,代码来源:Bootstrapper.cs

示例11: ApplicationStartup

        /// <summary>
        /// Applications the startup.
        /// </summary>
        /// <param name="container">The container.</param>
        /// <param name="pipelines">The pipelines.</param>
        protected override void ApplicationStartup(TinyIoCContainer container, IPipelines pipelines)
        {
            base.ApplicationStartup(container, pipelines);

            pipelines.BeforeRequest += ctx =>
            {
                var identity = (WindowsIdentity)HttpContext.Current.User.Identity;
                if (identity.IsAuthenticated)
                {
                    // Resolve<UserManager>
                    // Get from DB/Cache
                    // Add user to ICurrentUSerProvider
                    // Get Claims

                    ctx.CurrentUser = new DemoUserIdentity
                    {
                        UserName = identity.Name,
                        Claims = new[] { "Basic", "Finance" }
                    };
                }

                return null;
            };

            pipelines.AfterRequest += ctx =>
            {
                // If status code comes back as Unauthorized then
                // forward the user to the unauthorised page
                //if (ctx.Response.StatusCode == HttpStatusCode.Unauthorized
                //    || ctx.Response.StatusCode == HttpStatusCode.Forbidden)
                //{
                //    ctx.Response = new RedirectResponse("/Unauthorised");
                //}
            };
        }
开发者ID:caodaiming,项目名称:Snippets,代码行数:40,代码来源:CustomBootstrapper.cs

示例12: RequestStartup

        protected override void RequestStartup(IWindsorContainer container, IPipelines pipelines, NancyContext context)
        {
            //var formsAuthConfiguration = new FormsAuthenticationConfiguration
            //{
            //    RedirectUrl = "/login",
            //    UserMapper = container.Resolve<IUserMapper>(),
            //};
            //FormsAuthentication.Enable(pipelines, formsAuthConfiguration);

            pipelines.BeforeRequest.AddItemToEndOfPipeline(ctx =>
            {
                if (ctx.CurrentUser != null) ctx.ViewBag.UserName = ctx.CurrentUser.UserName;
                return null;
            });

            pipelines.BeforeRequest.AddItemToStartOfPipeline(nancyContext =>
            {
                //nancyContext.Request.Headers.UserAgent = "Lightstone";
                var token = "";
                var cookie = nancyContext.Request.Headers.Cookie.FirstOrDefault(x => (x.Name + "").ToLower() == "token");
                if (cookie != null)
                    token = HttpUtility.UrlDecode(cookie.Value);
                    //nancyContext.Request.Headers.Authorization = "Token {0}".FormatWith(HttpUtility.UrlDecode(token.Value));

                var user = container.Resolve<ITokenizer>().Detokenize(token, nancyContext, new DefaultUserIdentityResolver());
                if (user != null)
                    nancyContext.CurrentUser = user;
                return null;
            });
            TokenAuthentication.Enable(pipelines, new TokenAuthenticationConfiguration(container.Resolve<ITokenizer>()));
        }
开发者ID:rjonker1,项目名称:lightstone-data-platform,代码行数:31,代码来源:Bootstrapper.cs

示例13: ApplicationStartup

    protected override void ApplicationStartup(TinyIoCContainer container, IPipelines pipelines)
    {
      base.ApplicationStartup(container, pipelines);

      // Add an error handler to catch our entity not found exceptions
      pipelines.OnError += (context, exception) =>
      {
        // If we've raised an EntityNotFound exception in our data layer
        if (exception is EntityNotFoundException)
          return new Response()
          {
            StatusCode = HttpStatusCode.NotFound,
            ContentType = "text/html",
            Contents = (stream) =>
            {
              var errorMessage = Encoding.UTF8.GetBytes("A Data Entity with the requested ID was not found in the database.");
              stream.Write(errorMessage, 0, errorMessage.Length);
            }
          };

        // If none of the above handles our exception, then pass it on as a 500
        throw exception;
      };
      // End error handler

      CookieBasedSessions.Enable(pipelines);

    }
开发者ID:RickIsWright,项目名称:nancyfxbook,代码行数:28,代码来源:CustomBootstrapper.cs

示例14: RequestStartup

        protected override void RequestStartup(ILifetimeScope container, IPipelines pipelines, NancyContext context)
        {
            // No registrations should be performed in here, however you may
            // resolve things that are needed during request startup.

            FormsAuthentication.Enable(pipelines, new FormsAuthenticationConfiguration()
            {
                RedirectUrl = "~/account/login",
                UserMapper = container.Resolve<IUserMapper>(),
            });

            pipelines.BeforeRequest.AddItemToEndOfPipeline(c =>
            {
                if (c.CurrentUser.IsAuthenticated())
                {
                    container.Resolve<ITenantContext>().SetTenantId(c.CurrentUser.AsAuthenticatedUser().Id, c.CurrentUser.HasClaim("Admin"));
                    c.ViewBag.UserName = c.CurrentUser.AsAuthenticatedUser().FullName;
                    c.ViewBag.IsAdmin = c.CurrentUser.HasClaim("Admin");
                }
                else
                    container.Resolve<ITenantContext>().SetTenantId(null, false);

                return null;
            });
        }
开发者ID:kcornelis,项目名称:FreelanceManager.NET,代码行数:25,代码来源:NancyTestBootstrapper.cs

示例15: ApplicationStartup

        protected override void ApplicationStartup(ILifetimeScope container, IPipelines pipelines)
        {
            base.ApplicationStartup(container, pipelines);

            // register interfaces/implementations
            container.Update(builder => builder
                //.RegisterType<CouchDbTShirtRepository>()
                .RegisterType<MockedTShirtRepository>()
                .As<ITShirtRepository>());

            // register MyCouchStore parameter for couchdb repo classes
            container.Update(builder => builder
                .RegisterType<MyCouchStore>()
                .As<IMyCouchStore>()
                .UsingConstructor(typeof (string), typeof (string))
                .WithParameters(new [] {
                    new NamedParameter("dbUri","http://seraya_dba:[email protected]:5984/"),
                    new NamedParameter("dbName","cshirts")
                })
            );

            // TODO: remove after implementing REST-Api & replacing razor with angular
            // display razor error messages
            StaticConfiguration.DisableErrorTraces = false;
        }
开发者ID:takahser,项目名称:C-Shirts,代码行数:25,代码来源:Bootstrapper.cs


注:本文中的IPipelines类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。