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


C# IOwinContext类代码示例

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


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

示例1: Invoke

        public override async Task Invoke(IOwinContext context)
        {
            Func<IDictionary<string, object>, object> func;
            if (_config.TryGetValue(context.Request.Path, out func))
            {
                try
                {
                    var result = func(context.Request.ToDatabag()) ?? new { };
                    context.Response.Write(result.ToJsonString());

                    await Next.Invoke(context);
                }
                catch (Exception e)
                {
                    context.Response.StatusCode = (int)HttpStatusCode.InternalServerError;
                    var jsonString = new { exception = e.ToString() }.ToJsonString();
                    context.Response.Write(jsonString);
                }
            }
            else
            {
                // Returns 404
                context.Response.StatusCode = (int)HttpStatusCode.NotFound;
            }
        }
开发者ID:art2003,项目名称:Medidata.Cloud.Thermometer,代码行数:25,代码来源:ActionRouteMiddleware.cs

示例2: Invoke

        public override Task Invoke(IOwinContext context)
        {
            string header;
            switch (_xFrameOptions)
            {
                case XFrameOptions.Deny:
                    header = XFrameOptionsConstants.Deny;
                    break;

                case XFrameOptions.Sameorigin:
                    header = XFrameOptionsConstants.Sameorigin;
                    break;

                case XFrameOptions.AllowFrom:
                    header = string.Format(XFrameOptionsConstants.AllowFrom, _uri);
                    break;

                default:
                    header = XFrameOptionsConstants.Sameorigin;
                    break;
            }

            var headers = context.Response.Headers;
            if (headers.ContainsKey(XFrameOptionsConstants.Header))
            {
                headers[XFrameOptionsConstants.Header] = header;
            }
            else
            {
                headers.Append(XFrameOptionsConstants.Header, header);
            }

            return Next.Invoke(context);
        }
开发者ID:ilich,项目名称:OnDotNet.Owin.Shield,代码行数:34,代码来源:FrameguardMiddleware.cs

示例3: Invoke

        public override Task Invoke(IOwinContext context)
        {
            var dispatcher = _routes.FindDispatcher(context.Request.Path.Value);
            
            if (dispatcher == null)
            {
                return Next.Invoke(context);
            }

            foreach (var filter in _authorizationFilters)
            {
                if (!filter.Authorize(context.Environment))
                {
                    context.Response.StatusCode = (int) HttpStatusCode.Unauthorized;
                    return Task.FromResult(false);
                }
            }

            var dispatcherContext = new RequestDispatcherContext(
                _appPath,
                _storage,
                context.Environment,
                dispatcher.Item2);

            return dispatcher.Item1.Dispatch(dispatcherContext);
        }
开发者ID:GitHuang,项目名称:Hangfire,代码行数:26,代码来源:DashboardMiddleware.cs

示例4: InvokeNext

 private async Task InvokeNext(IOwinContext context)
 {
     if (Next != null)
     {
         await Next.Invoke(context);
     }
 }
开发者ID:estei,项目名称:Owin.Hsts,代码行数:7,代码来源:HstsMiddleware.cs

示例5: Apply

        public static void Apply(this CommandResult commandResult, IOwinContext context)
        {
            if (commandResult == null)
            {
                throw new ArgumentNullException("commandResult");
            }

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

            context.Response.ContentType = commandResult.ContentType;
            context.Response.StatusCode = (int)commandResult.HttpStatusCode;

            if (commandResult.Location != null)
            {
                context.Response.Headers["Location"] = commandResult.Location.OriginalString;
            }

            if (commandResult.Content != null)
            {
                using (var writer = new StreamWriter(context.Response.Body, Encoding.UTF8, 1024, true))
                {
                    writer.Write(commandResult.Content);
                }
            }
        }
开发者ID:Raschmann,项目名称:authservices,代码行数:28,代码来源:CommandResultExtensions.cs

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

示例7: Invoke

        async Task Invoke(IOwinContext context)
        {
            string error = null;

            try
            {
                switch (context.Request.Method)
                {
                    case "GET":
                        await InvokeGET(context);
                        break;
                    case "POST":
                        await InvokePOST(context);
                        break;
                    default:
                        await context.Response.WriteAsync("NotFound");
                        context.Response.StatusCode = (int)HttpStatusCode.NotFound;
                        break;
                }
            }
            catch (Exception e)
            {
                error = e.Message;
            }

            if (error != null)
            {
                context.Response.StatusCode = (int)HttpStatusCode.InternalServerError;
            }
        }
开发者ID:jinujoseph,项目名称:NuGet.Services.Metadata,代码行数:30,代码来源:Startup.cs

示例8: InvokeGET

        async Task InvokeGET(IOwinContext context)
        {
            switch (context.Request.Path.Value)
            {
                case "/":
                    {
                        context.Response.Write("OK");
                        context.Response.StatusCode = (int)HttpStatusCode.OK;
                        break;
                    }
                case "/claims":
                    {
                        JArray result = new JArray();
                        foreach (Claim claim in ClaimsPrincipal.Current.Claims)
                        {
                            JObject obj = new JObject();
                            obj.Add("type", claim.Type);
                            obj.Add("value", claim.Value);
                            result.Add(obj);
                        }

                        await context.Response.WriteAsync(result.ToString());
                        context.Response.ContentType = "application/json";
                        context.Response.StatusCode = (int)HttpStatusCode.OK;
                        break;
                    }
                default:
                    {
                        await context.Response.WriteAsync("NotFound");
                        context.Response.StatusCode = (int)HttpStatusCode.NotFound;
                        break;
                    }
            }
        }
开发者ID:jinujoseph,项目名称:NuGet.Services.Metadata,代码行数:34,代码来源:Startup.cs

示例9:

 void IOwinContextCleaner.Clean(IOwinContext context)
 {
     if (context.Environment.ContainsKey(QOMVC_PLUGIN_KEY))
         context.Environment.Remove(QOMVC_PLUGIN_KEY);
     if (context.Environment.ContainsKey(QOMVC_PATH_KEY))
         context.Environment.Remove(QOMVC_PATH_KEY);
 }
开发者ID:aaasoft,项目名称:Quick.OwinMVC,代码行数:7,代码来源:AbstractPluginPathMiddleware.cs

示例10: ProcessRequest

		/// <summary>
		/// Processes the HTTP request for controllers.
		/// </summary>
		/// <param name="containerProvider">The DI container provider.</param>
		/// <param name="context">The context.</param>
		/// <returns></returns>
		public Task ProcessRequest(IDIContainerProvider containerProvider, IOwinContext context)
		{
			var result = _controllersProcessor.ProcessControllers(containerProvider, context);

			switch (result)
			{
				case ControllersProcessorResult.Ok:
					return _pageProcessor.ProcessPage(containerProvider, context);

				case ControllersProcessorResult.Http401:
					context.Response.StatusCode = 401;
					_redirector.SetLoginReturnUrlFromCurrentUri();
					break;

				case ControllersProcessorResult.Http403:
					context.Response.StatusCode = 403;
					break;

				case ControllersProcessorResult.Http404:
					context.Response.StatusCode = 404;
					break;
			}

			return Task.Delay(0);
		}
开发者ID:i4004,项目名称:Simplify.Web,代码行数:31,代码来源:ControllersRequestHandler.cs

示例11: Invoke

        public Task Invoke(IOwinContext context, Func<Task> next)
        {
            var content = new StringBuilder();
            content.Append("The Urchin Server failed to initialize correctly on ");
            content.Append(Environment.MachineName);
            content.Append(".\n");
            content.Append("There is a configuration error in Urchin, or a failure in something that Urchin depends on.\n\n");
            content.Append("Check the error log for more detailed information.\n\n");
            if (_exception != null)
            {
                content.Append("The exception that was caught was ");
                content.Append(_exception.GetType().FullName);
                content.Append("\n");
                content.Append(_exception.Message);
                content.Append("\n");
                if (_exception.StackTrace != null)
                {
                    content.Append(_exception.StackTrace);
                    content.Append("\n");
                }
                var inner = _exception.InnerException;
                while (inner != null)
                {
                    content.Append("The inner exception was ");
                    content.Append(inner.GetType().FullName);
                    content.Append("\n");
                    content.Append(inner.Message);
                    content.Append("\n");
                    inner = inner.InnerException;
                }
            }

            context.Response.ContentType = "text/plain";
            return context.Response.WriteAsync(content.ToString());
        }
开发者ID:Bikeman868,项目名称:Urchin,代码行数:35,代码来源:FailedSetupMiddleware.cs

示例12: CheckToken

        private async Task<bool> CheckToken(IOwinContext context)
        {
            if (!_options.RequireBearerToken)
            {
                return true;
            }

            if (!string.IsNullOrWhiteSpace(_options.BearerTokenValue))
            {
                const string bearerTypeToken = "Bearer";

                var authorizationHeaders = context.Request.Headers.GetValues("Authorization");
                if (authorizationHeaders != null && authorizationHeaders.Count > 0)
                {
                    var header = authorizationHeaders[0].Trim();
                    if (header.StartsWith(bearerTypeToken))
                    {
                        var value = header.Substring(bearerTypeToken.Length).Trim();
                        if (!value.Equals(_options.BearerTokenValue))
                        {
                            context.Response.ContentType = "text/plain";
                            context.Response.StatusCode = (int)HttpStatusCode.Forbidden;
                            await context.Response.WriteAsync("Forbidden");
                            return false;
                        }
                        return true;
                    }
                }
            }
            context.Response.ContentType = "text/plain";
            context.Response.StatusCode = (int)HttpStatusCode.Unauthorized;
            await context.Response.WriteAsync("Unauthorized");
            return false;
        }
开发者ID:NetChris,项目名称:NetChris.Web.SelfTest,代码行数:34,代码来源:SelfTestMiddleware.cs

示例13: SignInAsAlice

 private Task SignInAsAlice(IOwinContext context)
 {
     context.Authentication.SignIn(
         new AuthenticationProperties(),
         new ClaimsIdentity(new GenericIdentity("Alice", "Cookies")));
     return Task.FromResult<object>(null);
 }
开发者ID:ricardodemauro,项目名称:katana-clone,代码行数:7,代码来源:CookieMiddlewareTests.cs

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

示例15: OpenIdConnectValidateClientRedirectUriContext

 internal OpenIdConnectValidateClientRedirectUriContext(
     IOwinContext context,
     OpenIdConnectServerOptions options,
     OpenIdConnectMessage authorizationRequest)
     : base(context, options, authorizationRequest)
 {
 }
开发者ID:cleancodenz,项目名称:WebAPI,代码行数:7,代码来源:OpenIdConnectValidateClientRedirectUriContext.cs


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