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


C# IOwinRequest类代码示例

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


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

示例1: GetTenantInstance

        private async Task<TenantInstance> GetTenantInstance(IOwinRequest request)
        {
            var requestIdentifier = configuration.IdentificationStrategy(request);

            if (requestIdentifier == null)
            {
                throw new InvalidOperationException("The identification strategy did not return an identifier for the request.");
            }

            var instance = runningInstances.Get(requestIdentifier);

            if (instance != null)
            {
                Log("Instance for '{0}' is already running.", requestIdentifier);
                return instance;
            }

            Log("Instance for '{0}' not running. Resolving tenant.", requestIdentifier);

            var tenant = await configuration.TenantResolver.Resolve(requestIdentifier);

            if (tenant != null)
            {
                Log("Tenant found with identifiers '{0}'", string.Join(",", tenant.RequestIdentifiers));
                instance = StartInstance(tenant);
            }

            return instance;
        }
开发者ID:nicolocodev,项目名称:saaskit,代码行数:29,代码来源:SaasKitEngine.cs

示例2: GetCorsPolicyAsync

        public async Task<System.Web.Cors.CorsPolicy> GetCorsPolicyAsync(IOwinRequest request)
        {
            var path = request.Path.ToString();
            var origin = request.Headers["Origin"];

            // see if the Origin is different than this server's origin. if so
            // that indicates a proper CORS request
            var ctx = new OwinContext(request.Environment);
            // using GetIdentityServerHost takes into account a configured PublicOrigin
            var thisOrigin = ctx.GetIdentityServerHost();
            if (origin != null && origin != thisOrigin)
            {
                if (IsPathAllowed(request))
                {
                    Logger.InfoFormat("CORS request made for path: {0} from origin: {1}", path, origin);

                    if (await IsOriginAllowed(origin, request.Environment))
                    {
                        Logger.Info("CorsPolicyService allowed origin");
                        return Allow(origin);
                    }
                    else
                    {
                        Logger.Info("CorsPolicyService did not allow origin");
                    }
                }
                else
                {
                    Logger.InfoFormat("CORS request made for path: {0} from origin: {1} but rejected because invalid CORS path", path, origin);
                }
            }

            return null;
        }
开发者ID:Rolosoft,项目名称:IdentityServer3,代码行数:34,代码来源:CorsPolicyProvider.cs

示例3: GetCorsPolicyAsync

        public async Task<System.Web.Cors.CorsPolicy> GetCorsPolicyAsync(IOwinRequest request)
        {
            var path = request.Path.ToString();
            var origin = request.Headers["Origin"];

            // see if the Origin is different than this server's origin. if so
            // that indicates a proper CORS request
            var thisOrigin = request.Uri.Scheme + "://" + request.Uri.Authority;
            if (origin != null && origin != thisOrigin)
            {
                if (IsPathAllowed(request))
                {
                    Logger.InfoFormat("CORS request made for path: {0} from origin: {1}", path, origin);

                    if (await IsOriginAllowed(origin, request.Environment))
                    {
                        Logger.Info("CorsPolicyService allowed origin");
                        return Allow(origin);
                    }
                    else
                    {
                        Logger.Info("CorsPolicyService did not allow origin");
                    }
                }
                else
                {
                    Logger.WarnFormat("CORS request made for path: {0} from origin: {1} but rejected because invalid CORS path", path, origin);
                }
            }

            return null;
        }
开发者ID:ridopark,项目名称:IdentityServer3,代码行数:32,代码来源:CorsPolicyProvider.cs

示例4: ValidateTicket

        public async Task<AuthenticationTicket> ValidateTicket(IOwinRequest request, IOwinContext context, HttpClient httpClient,
            string ticket, AuthenticationProperties properties, string service)
        {
            // Now, we need to get the ticket validated
            string validateUrl = _options.CasServerUrlBase + "/validate" +
                                 "?service=" + service +
                                 "&ticket=" + Uri.EscapeDataString(ticket);

            HttpResponseMessage response = await httpClient.GetAsync(validateUrl, request.CallCancelled);

            response.EnsureSuccessStatusCode();
            string responseBody = await response.Content.ReadAsStringAsync();


            String validatedUserName = null;
            var responseParts = responseBody.Split('\n');
            if (responseParts.Length >= 2 && responseParts[0] == "yes")
                validatedUserName = responseParts[1];

            if (!String.IsNullOrEmpty(validatedUserName))
            {
                var identity = new ClaimsIdentity(_options.AuthenticationType);
                identity.AddClaim(new Claim(ClaimTypes.NameIdentifier, validatedUserName, "http://www.w3.org/2001/XMLSchema#string", _options.AuthenticationType));
                identity.AddClaim(new Claim(ClaimTypes.Name, validatedUserName, "http://www.w3.org/2001/XMLSchema#string", _options.AuthenticationType));

                var authenticatedContext = new CasAuthenticatedContext(context, identity, properties);

                await _options.Provider.Authenticated(authenticatedContext);

                return new AuthenticationTicket(authenticatedContext.Identity, authenticatedContext.Properties);
            }

            return new AuthenticationTicket(null, properties);
        }
开发者ID:ambassadorJ,项目名称:Owin.Security.CAS,代码行数:34,代码来源:Cas1ValidateTicketValidator.cs

示例5: Inbound

 private void Inbound(IOwinRequest request, string beforeValue)
 {
     if (beforeValue != null)
     {
         RouteParams.Set(request.Environment, inRouteParam, beforeValue);
     }
 }
开发者ID:Xamarui,项目名称:OwinUtils,代码行数:7,代码来源:RouteCookie.cs

示例6: CheckRequiredRequestParameter

 public static string CheckRequiredRequestParameter(IOwinRequest request, IList<string> errors, string name)
 {
     if (string.IsNullOrEmpty(request.Query[name]))
     {
         errors.Add(string.Format("required property '{0}' is missing from metadata", name));
     }
     return request.Query[name];
 }
开发者ID:jinujoseph,项目名称:NuGet.Services.Metadata,代码行数:8,代码来源:ValidationHelpers.cs

示例7: GetScimVersion

        private static ScimVersion GetScimVersion(IOwinRequest request, ScimServerConfiguration serverConfiguration)
        {
            var result = _VersionRegex.Match(request.Path.ToString());
            if (result.Success)
                return new ScimVersion(result.Groups[1].Value); // e.g. groups[] -> /v0/, v0

            return serverConfiguration.DefaultScimVersion;
        }
开发者ID:PowerDMS,项目名称:Owin.Scim,代码行数:8,代码来源:AmbientRequestService.cs

示例8: allowCompress

 private Boolean allowCompress(IOwinRequest req)
 {
     if (!EnableCompress)
         return false;
     var acceptEncoding = req.Headers.Get("Accept-Encoding");
     if (acceptEncoding == null)
         return false;
     return acceptEncoding.Contains("gzip");
 }
开发者ID:HongJunRen,项目名称:Quick.OwinMVC,代码行数:9,代码来源:AbstractPluginPathMiddleware.cs

示例9: IsAjaxRequest

 private static bool IsAjaxRequest(IOwinRequest request)
 {
     IReadableStringCollection query = request.Query;
     if ((query != null) && (query["X-Requested-With"] == "XMLHttpRequest"))
     {
         return true;
     }
     IHeaderDictionary headers = request.Headers;
     return ((headers != null) && (headers["X-Requested-With"] == "XMLHttpRequest"));
 }
开发者ID:gotcreme,项目名称:HighCharts1,代码行数:10,代码来源:Startup.cs

示例10: Log

        public void Log(IOwinRequest request, IOwinResponse response, long responseTime)
        {
            var username = (string.IsNullOrEmpty(request.User?.Identity?.Name)) ? "-" : request.User.Identity.Name;
            var queryString = string.IsNullOrEmpty(request.QueryString.Value) ? "-" : request.QueryString.Value;
            var useragent = (request.Headers.Get("User-Agent") ?? "-").Replace(' ', '+');
            var referer = request.Headers.Get("Referer") ?? "-";
            var message = $"{DateTime.UtcNow:yyyy-MM-dd HH:mm:ss} {ApplicationName} {ComputerName} {request.LocalIpAddress} {request.Method} {request.Uri.GetLeftPart(UriPartial.Path)} {queryString} {request.LocalPort} {username} {request.RemoteIpAddress} {useragent} {referer} {response.StatusCode} 0 0 {responseTime}";

            RequestLog.Warn(message);
        }
开发者ID:ctigeek,项目名称:FileAuditManager,代码行数:10,代码来源:ApiRequestLogger.cs

示例11: HasValidHeaders

        internal static bool HasValidHeaders(IOwinRequest request)
        {
            if (request.Accept == null || !request.Accept.ToLowerInvariant().Contains(ApplicationJsonMediaType))
                return false;

            if (!request.ContentType.ToLowerInvariant().StartsWith(ApplicationJsonMediaType))
                return false;

            return true;
        }
开发者ID:Xamarui,项目名称:GNaP.Owin.Authentication.Jwt,代码行数:10,代码来源:RequestValidator.cs

示例12: LogRequest

        private static async Task LogRequest(IOwinRequest request)
        {
            var reqLog = new
            {
                Method = request.Method,
                Url = request.Uri.AbsoluteUri,
                Headers = request.Headers,
                Body = await request.ReadBodyAsStringAsync()
            };

            Logger.Debug("HTTP Request" + Environment.NewLine + LogSerializer.Serialize(reqLog));
        }
开发者ID:284247028,项目名称:IdentityServer3,代码行数:12,代码来源:ConfigureHttpLoggingExtension.cs

示例13: GetRequest

        public IRequest GetRequest(IOwinRequest request)
        {
            using (StreamReader sr = new StreamReader(request.Body))
            {
                using (JsonReader reader = new JsonTextReader(sr))
                {
                    var iRequest = new Request(request.Query.Get("interface"), request.Query.Get("method"), JArray.Load(reader));

                    return iRequest;
                }
            }
        }
开发者ID:shanegrueling,项目名称:Genkan,代码行数:12,代码来源:Factory.cs

示例14: Resolve

        /// <summary>
        /// Resolves a tenant request using hostname
        /// </summary>
        /// <param name="request">The request</param>
        /// <returns>The tenant or null</returns>
        public ITenant Resolve(IOwinRequest request)
        {
            var httpContext = request.Context.Get<HttpContextWrapper>("System.Web.HttpContextBase");
            var routeData = RouteTable.Routes.GetRouteData(httpContext);

            if (routeData == null || routeData.Values.ContainsKey(RouteName) == false)
                return Tenants.First();

            var tenant = Tenants.FirstOrDefault(x => x.Name == routeData.Values[RouteName].ToString());

            return tenant ?? Tenants.First();
        }
开发者ID:fortunearterial,项目名称:tenantcore,代码行数:17,代码来源:RouteTenantResolver.cs

示例15: GetCompressor

        private ICompressor GetCompressor(IOwinRequest request)
        {
            if(!request.Headers.ContainsKey(AcceptEncoding))
            {
                return null;
            }

            return (from c in compressors
                    from e in request.Headers.GetCommaSeparatedValues(AcceptEncoding).Select(x => StringWithQualityHeaderValue.Parse(x))
                    orderby e.Quality descending
                    where string.Compare(c.ContentEncoding, e.Value, StringComparison.InvariantCultureIgnoreCase) == 0
                    select c).FirstOrDefault();
        }
开发者ID:mikegore1000,项目名称:SqueezeMe,代码行数:13,代码来源:CompressionMiddleware.cs


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