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


C# IOwinContext.Set方法代码示例

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


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

示例1: Success

 private static Task Success(IOwinContext context)
 {
     context.Response.StatusCode = 200;
     context.Set("test.PathBase", context.Request.PathBase.Value);
     context.Set("test.Path", context.Request.Path.Value);
     return Task.FromResult<object>(null);
 }
开发者ID:Kstal,项目名称:Microsoft.Owin,代码行数:7,代码来源:MapPathMiddlewareTests.cs

示例2: 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

示例3: Invoke

 public override Task Invoke(IOwinContext context)
 {
     context.Set<string>("p1", p1);
     context.Set<int>("p2", p2);
     context.Set<object>("p3", p3);
     return this.Next.Invoke(context);
 }
开发者ID:Xamarui,项目名称:Katana,代码行数:7,代码来源:OwinMiddlewareFacts.cs

示例4: Invoke

 public async override Task Invoke(IOwinContext context)
 {
     using (IDependencyScope scope = Resolver.BeginScope())
     {
         context.Set<IDependencyScope>(scope);
         context.Set<ManahostManagerDAL>((ManahostManagerDAL)scope.GetService(typeof(ManahostManagerDAL)));
         var scopeUnity = scope as UnityResolver;
         scopeUnity.RegisterInstance(new UnityRegisterScope() { Scope = scope });
         await Next.Invoke(context);
     }
 }
开发者ID:charla-n,项目名称:ManahostManager,代码行数:11,代码来源:WebApiApplication.Identity.cs

示例5: InspectStatusCode

 private bool InspectStatusCode(IOwinContext context)
 {
     StatusCodeAction action;
     string link;
     int statusCode = context.Response.StatusCode;
     if (options.StatusCodeActions.TryGetValue(statusCode, out action)
         && action == StatusCodeAction.ReplaceResponseWithKittens
         && links.TryGetValue(statusCode, out link))
     {
         context.Set<bool?>(ReplacementKey, true);
         return action == StatusCodeAction.ReplaceResponseWithKittens;
     }
     context.Set<bool?>(ReplacementKey, false);
     return false;
 }
开发者ID:Tratcher,项目名称:Owin-Dogfood,代码行数:15,代码来源:KittenStatusCodeMiddleware.cs

示例6: 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

示例7: 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

示例8: 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

示例9: Invoke

        public override async Task Invoke(IOwinContext context)
        {
            try
            {
                await Next.Invoke(context);
            }
            catch (Exception ex)
            {
                var rep = context.Response;
                rep.StatusCode = 500;
                try
                {
                    if (String.IsNullOrEmpty(RewritePath))
                    {
                        var result = ApiResult.Error("500 内部错误", new ExceptionInfo(ex)).ToString();

                        rep.ContentType = "text/json; charset=UTF-8";
                        byte[] content = encoding.GetBytes(result);
                        rep.ContentLength = content.Length;
                        await context.Response.WriteAsync(content);
                        return;
                    }

                    context.Set("Exception", ex);
                    context.Set("owin.RequestPath", RewritePath);

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

                    await Next.Invoke(context);
                    if (rep.StatusCode == 404)
                        throw ex;
                }
                catch (Exception ex2)
                {
                    rep.ContentType = "text/plain; charset=UTF-8";
                    byte[] content = encoding.GetBytes(ex2.ToString());
                    rep.ContentLength = content.Length;
                    await context.Response.WriteAsync(content);
                }
            }
        }
开发者ID:aaasoft,项目名称:Quick.OwinMVC,代码行数:43,代码来源:Error500Middleware.cs

示例10: Invoke

        public override Task Invoke(IOwinContext context)
        {
            String path = context.Get<String>("owin.RequestPath");
            //设置原始请求路径
            context.Set("Quick.OwinMVC.SourceRequestPath", path);
            StringBuilder sb = new StringBuilder();
            for (int i = 0; i < path.Split('/').Length - 2; i++)
            {
                if (i > 0)
                    sb.Append("/");
                sb.Append("..");
            }
            var contextPath = sb.ToString();
            if (String.IsNullOrEmpty(contextPath))
                contextPath = ".";

            context.Set("ContextPath", contextPath);
            return Next.Invoke(context);
        }
开发者ID:HongJunRen,项目名称:Quick.OwinMVC,代码行数:19,代码来源:MiddlewareContext.cs

示例11: Invoke

 public async override Task Invoke(IOwinContext context)
 {
     var timewatch = Stopwatch.StartNew();
     context.Set(RequestStopwatchLogKey, GetLogs());
     await Next.Invoke(context);
     timewatch.Stop();
     lock (_logs)
     {
         _logs.Add(new RequestStopwatchLog(context.Request.Path.ToString(), timewatch.ElapsedMilliseconds));
     }
 }
开发者ID:pvasek,项目名称:RazorCompilationOfDynamicObjects,代码行数:11,代码来源:RequestStopwatchMiddleware.cs

示例12: Invoke

        public override Task Invoke(IOwinContext context)
        {
            return Task.Factory.StartNew(() =>
            {
                try
                {
                    Next.Invoke(context).Wait();
                }
                catch (Exception ex)
                {
                    var rep = context.Response;
                    rep.StatusCode = 500;
                    try
                    {
                        if (String.IsNullOrEmpty(RewritePath))
                            throw new ArgumentNullException($"Property '{this.GetType().FullName}.{RewritePath}' must be set.");

                        context.Set("Exception", ex);
                        context.Set("owin.RequestPath", RewritePath);

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

                        Next.Invoke(context).Wait();
                        if (rep.StatusCode == 404)
                            throw ex;
                    }
                    catch (Exception ex2)
                    {
                        rep.ContentType = "text/plain; charset=UTF-8";
                        byte[] content = encoding.GetBytes(ex2.ToString());
                        rep.ContentLength = content.Length;
                        context.Response.Write(content);
                    }
                }
            });
        }
开发者ID:HongJunRen,项目名称:Quick.OwinMVC,代码行数:38,代码来源:Error500Middleware.cs

示例13: Invoke

        public override async Task Invoke(IOwinContext context)
        {
            InitializeOperationIdContext(context);

            try
            {
                await Next.Invoke(context);
            }
            finally
            {
                context.Set<string>(Consts.OperationIdContextKey, null);
                OperationIdContext.Clear();
            }
        }
开发者ID:marcinbudny,项目名称:applicationinsights-owinextensions,代码行数:14,代码来源:OperationIdContextMiddleware.cs

示例14: Invoke

        /// <summary>
        /// Process an individual request.
        /// </summary>
        public override async Task Invoke(IOwinContext context)
        {
            if (Interlocked.Exchange(ref configurationSaved, 1) == 0) {
                VisualStudioHelper.DumpConfiguration(Configuration, Configuration.ApplicationPhysicalPath);
            }
            // create the context
            var dotvvmContext = new DotvvmRequestContext()
            {
                OwinContext = context,
                Configuration = Configuration,
                ResourceManager = new ResourceManager(Configuration),
                ViewModelSerializer = Configuration.ServiceLocator.GetService<IViewModelSerializer>()
            };
            context.Set(HostingConstants.DotvvmRequestContextOwinKey, dotvvmContext);

            // attempt to translate Googlebot hashbang espaced fragment URL to a plain URL string.
            string url;
            if (!TryParseGooglebotHashbangEscapedFragment(context.Request.QueryString, out url))
            {
                url = context.Request.Path.Value;
            }
            url = url.Trim('/');

            // find the route
            IDictionary<string, object> parameters = null;
            var route = Configuration.RouteTable.FirstOrDefault(r => r.IsMatch(url, out parameters));

            if (route != null)
            {
                // handle the request
                dotvvmContext.Route = route;
                dotvvmContext.Parameters = parameters;
                dotvvmContext.Query = context.Request.Query
                    .ToDictionary(d => d.Key, d => d.Value.Length == 1 ? (object) d.Value[0] : d.Value);

                try
                {
                    await route.ProcessRequest(dotvvmContext);
                    return;
                }
                catch (DotvvmInterruptRequestExecutionException)
                {
                    // the response has already been generated, do nothing
                    return;
                }
            }
            
            // we cannot handle the request, pass it to another component
            await Next.Invoke(context);
        }
开发者ID:darilek,项目名称:dotvvm,代码行数:53,代码来源:DotvvmMiddleware.cs

示例15: InitializeOperationIdContext

        private void InitializeOperationIdContext(IOwinContext context)
        {
            string idContextKey;

            if (_configuration.ShouldTryGetIdFromHeader && 
                TryGetIdFromHeader(context, out idContextKey))
            {
                OperationIdContext.Set(idContextKey);
            }
            else
            {
                OperationIdContext.Create();
            }

            context.Set(Consts.OperationIdContextKey, OperationIdContext.Get());
        }
开发者ID:marcinbudny,项目名称:applicationinsights-owinextensions,代码行数:16,代码来源:OperationIdContextMiddleware.cs


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