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


C# IOwinContext.Get方法代码示例

本文整理汇总了C#中IOwinContext.Get方法的典型用法代码示例。如果您正苦于以下问题:C# IOwinContext.Get方法的具体用法?C# IOwinContext.Get怎么用?C# IOwinContext.Get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IOwinContext的用法示例。


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

示例1: Invoke

        public override async Task Invoke(IOwinContext context)
        {
            // Determine correlation id.
            var correlationId = context.Get<string>(OwinRequestIdKey);

            // The NuGet Gallery sends us the X-CorrelationId header.
            // If that header is present, override OWIN's owin.RequestId.
            string[] temp = null;
            if (context.Request.Headers.TryGetValue(CorrelationIdHeaderKey, out temp))
            {
                correlationId = temp[0];

                context.Set(OwinRequestIdKey, correlationId);
            }

            // As a bonus, make Serilog aware of this request ID as well.
            if (HttpContext.Current != null)
            {
                HttpContext.Current.Items[SerilogRequestIdItemName] = Guid.Parse(correlationId);
            }

            // Run all the things
            await Next.Invoke(context);

            // Set response header
            context.Response.Headers.Add("X-CorrelationId", new[] { context.Get<string>(OwinRequestIdKey) });
        }
开发者ID:NuGet,项目名称:NuGet.Services.Metadata,代码行数:27,代码来源:CorrelationIdMiddleware.cs

示例2: Invoke

 public override Task Invoke(IOwinContext context)
 {
     if (context.Get<string>("p1") == "p1" && context.Get<int>("p2") == 2 && context.Get<object>("p3").ToString() == "p3")
     {
         return context.Response.WriteAsync("SUCCESS");
     }
     else
     {
         return context.Response.WriteAsync("FAILURE");
     }
 }
开发者ID:Xamarui,项目名称:Katana,代码行数:11,代码来源:OwinMiddlewareFacts.cs

示例3: Invoke

        public override Task Invoke(IOwinContext context)
        {
            var rep = context.Response;
            rep.StatusCode = 404;

            //判断调用次数,避免无限递归
            var invokeTimes = context.Get<Int32>(INVOKE_TIMES);
            invokeTimes++;
            if (invokeTimes > 1 || String.IsNullOrEmpty(RewritePath))
            {
                String msg = "404 Not Found";
                rep.ContentLength = msg.Length;
                return rep.WriteAsync(msg);
            }
            context.Set(INVOKE_TIMES, invokeTimes);

            context.Set<String>("owin.RequestPath", RewritePath);
            OwinMiddleware first = server.GetFirstMiddlewareInstance();
            if (first == null)
                throw new ArgumentException($"Middleware '{this.GetType().FullName};{this.GetType().Assembly.GetName().Name}' must not be the first middleware,and recommand to be set to the last one.");

            //清理OwinContext
            foreach (var cleaner in server.GetMiddlewares<IOwinContextCleaner>())
                cleaner.Clean(context);

            return first.Invoke(context);
        }
开发者ID:aaasoft,项目名称:Quick.OwinMVC,代码行数:27,代码来源:Error404Middleware.cs

示例4: PrintCurrentIntegratedPipelineStage

 private void PrintCurrentIntegratedPipelineStage(IOwinContext context, string msg)
 {
     var currentIntegratedpipelineStage = HttpContext.Current.CurrentNotification;
     context.Get<TextWriter>("host.TraceOutput").WriteLine(
         "Current IIS event: " + currentIntegratedpipelineStage
         + " Msg: " + msg);
 }
开发者ID:TheFastCat,项目名称:OWINKatanaExamples,代码行数:7,代码来源:Startup.cs

示例5: Invoke

        /// <summary>
        /// Main entry point of middleware.
        /// </summary>
        /// <param name="context">Owin Context</param>
        /// <returns>Task</returns>
        public async override Task Invoke(IOwinContext context)
        {
            await Next.Invoke(context);

            var setCookie = context.Response.Headers.GetValues("Set-Cookie");
            if (setCookie != null)
            {
                var cookies = CookieParser.Parse(setCookie);

                foreach (var c in cookies)
                {
                    // Guard for stability, preventing nullref exception
                    // in case private reflection breaks.
                    if (fromHeaderProperty != null)
                    {
                        // Mark the cookie as coming from a header, to prevent
                        // System.Web from adding it again.
                        fromHeaderProperty.SetValue(c, true);
                    }

                    // HttpContext.Current turns to null in some cases after the
                    // async call to Next.Invoke() when run in a web forms
                    // application. Let's grab it from the owin environment
                    // instead.
                    var httpContext = context.Get<HttpContextBase>(typeof(HttpContextBase).FullName);

                    if (httpContext != null &&
                        !httpContext.Response.Cookies.AllKeys.Contains(c.Name))
                    {
                        httpContext.Response.Cookies.Add(c);
                    }
                }
            }
        }
开发者ID:jaymclain,项目名称:owin-cookie-saver,代码行数:39,代码来源:KentorOwinCookieSaverMiddleware.cs

示例6: CreateManager

        private static UserManager<IdentityUser> CreateManager(IdentityFactoryOptions<UserManager<IdentityUser>> options, IOwinContext context)
        {
            var userStore = new UserStore<IdentityUser>(context.Get<OAuthDbContext>());
            var manager = new UserManager<IdentityUser>(userStore);

            return manager;
        }
开发者ID:RolandTG,项目名称:AspNetIdentitySamples,代码行数:7,代码来源:Startup.cs

示例7: AuthenticationRepository

 public AuthenticationRepository(IOwinContext owinContext)
 {
     userManager = owinContext.GetUserManager<ApplicationUserManager>();
     roleManager = owinContext.Get<ApplicationRoleManager>();
     authenticationManager = owinContext.Authentication;
     request = owinContext.Request;
 }
开发者ID:CuongDuongDuy,项目名称:SecuredToDoList,代码行数:7,代码来源:AuthenticationRepository.cs

示例8: Invoke

 public async override Task Invoke(IOwinContext context)
 {
     context.Set(OriginalStreamKey, context.Response.Body);
     context.Response.Body = new StreamWrapper(context.Response.Body, InspectStatusCode, context);
     await Next.Invoke(context);
     
     StatusCodeAction action;
     string link;
     int statusCode = context.Response.StatusCode;
     bool? replace = context.Get<bool?>(ReplacementKey);
     if (!replace.HasValue)
     {
         // Never evaluated, no response sent yet.
         if (options.StatusCodeActions.TryGetValue(statusCode, out action)
             && links.TryGetValue(statusCode, out link)
             && action != StatusCodeAction.Ignore)
         {
             await SendKitten(context, link);
         }
     }
     else if (replace.Value == true)
     {
         if (links.TryGetValue(statusCode, out link))
         {
             await SendKitten(context, link);
         }
     }
 }
开发者ID:Tratcher,项目名称:Owin-Dogfood,代码行数:28,代码来源:KittenStatusCodeMiddleware.cs

示例9: Invoke

        public override Task Invoke(IOwinContext context)
        {
            validateStage(context, expectedStageName, middlewareId);
            context.Get<Stack<int>>("stack").Push(middlewareId);

            return this.Next.Invoke(context).ContinueWith((result) =>
            {
                validateStage(context, RequestNotification.EndRequest, middlewareId);

                var expectedMiddlewareId = context.Get<Stack<int>>("stack").Pop();
                if (expectedMiddlewareId != middlewareId)
                {
                    throw new Exception(string.Format(Error_Incorrect_Middleware_Unwinding, expectedMiddlewareId, middlewareId));
                }
            });
        }
开发者ID:Xamarui,项目名称:Katana,代码行数:16,代码来源:IntegratedPipelineMiddleware.cs

示例10: Create

        public static CategoryManager Create(IdentityFactoryOptions<CategoryManager> options, IOwinContext context)
        {
            ICategoryDataAccess categoryData = context.Get<SqlConnection>().As<ICategoryDataAccess>();
            CategoryManager manager = new CategoryManager(categoryData);

            return manager;
        }
开发者ID:okusnadi,项目名称:personal-finance,代码行数:7,代码来源:CategoryManager.cs

示例11: Service

 public string Service(IOwinContext context, IDictionary<string, object> data)
 {
     var rep = context.Response;
     context.GetSession().Clear();
     rep.Redirect(context.Get<String>("ContextPath"));
     return null;
 }
开发者ID:HongJunRen,项目名称:Quick.OwinMVC,代码行数:7,代码来源:LogoutController.cs

示例12: PaymentService

 public PaymentService(IUserService userService, IEmailService emailService)
 {
     _emailService = emailService;
     _userService = userService;
     _owin = HttpContext.Current.GetOwinContext();
     _dbContext = _owin.Get<ApplicationDbContext>();
 }
开发者ID:odinhaus,项目名称:SavingChance,代码行数:7,代码来源:PaymentService.cs

示例13: Create

        // callback function for IAppBuilder.CreatePerOwinContext
        public static AccountManager Create(IdentityFactoryOptions<AccountManager> options, IOwinContext context)
        {
            IAccountDataAccess accountData = context.Get<SqlConnection>().As<IAccountDataAccess>();
            AccountManager manager = new AccountManager(accountData);

            return manager;
        }
开发者ID:okusnadi,项目名称:personal-finance,代码行数:8,代码来源:AccountManager.cs

示例14: Invoke

        public Task Invoke(IOwinContext context, Func<Task> next)
        {
            var request = context.Request;
            if (request.Method != "GET" || !_path.IsWildcardMatch(request.Path))
                return next.Invoke();

            var environment = request.Query["environment"];
            var machine = request.Query["machine"];
            var application = request.Query["application"];
            var instance = request.Query["instance"];

            if (string.IsNullOrWhiteSpace(machine))
                throw new HttpException((int)HttpStatusCode.BadRequest, "Machine parameter is required");

            if (string.IsNullOrWhiteSpace(application))
                throw new HttpException((int)HttpStatusCode.BadRequest, "Application parameter is required");

            try
            {
                var clientCredentials = context.Get<IClientCredentials>("ClientCredentials");

                var config = _ruleData.TraceConfig(clientCredentials, environment, machine, application, instance);

                context.Response.ContentType = "application/json";
                return context.Response.WriteAsync(config.ToString(Formatting.Indented));
            }
            catch (Exception ex)
            {
                if (ex is HttpException) throw;
                throw new HttpException((int)HttpStatusCode.InternalServerError, ex.Message, ex);
            }
        }
开发者ID:Bikeman868,项目名称:Urchin,代码行数:32,代码来源:TraceEndpoint.cs

示例15: Invoke

 public override Task Invoke(IOwinContext context)
 {
     String path = context.Get<String>("owin.RequestPath");
     if (rewriteDict.ContainsKey(path))
         context.Set<String>("owin.RequestPath", rewriteDict[path]);
     return Next.Invoke(context);
 }
开发者ID:HongJunRen,项目名称:Quick.OwinMVC,代码行数:7,代码来源:RewriteMiddleware.cs


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