• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C# IOwinRequest类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: HandleMultipartData

 /// <summary>
 /// 处理多段表单数据
 /// </summary>
 /// <param name="req"></param>
 /// <param name="parameterHandler"></param>
 /// <param name="fileHandler"></param>
 public static void HandleMultipartData(IOwinRequest req,
     StreamingMultipartFormDataParser.ParameterDelegate parameterHandler,
     StreamingMultipartFormDataParser.FileStreamDelegate fileHandler,
     StreamingMultipartFormDataParser.StreamClosedDelegate streamClosedDelegate = null)
 {
     if (!req.ContentType.StartsWith("multipart/form-data;"))
         throw new ArgumentException("'ContentType' not start with 'multipart/form-data;'.");
     var parser = new StreamingMultipartFormDataParser(req.Body);
     parser.ParameterHandler = parameterHandler;
     parser.FileHandler = fileHandler;
     parser.StreamClosedHandler = streamClosedDelegate;
     parser.Run();
 }
开发者ID:aaasoft,项目名称:Quick.OwinMVC,代码行数:19,代码来源:MultipartFormDataUtils.cs


示例17: ExtractRequestParameters

        public async Task<WebApiLogger> ExtractRequestParameters(IOwinRequest request)
        {
            logEntry.RequestHeaders = await request.RequestHeadersToJsonString();
            logEntry.RequestContentBody = await request.RequestBodyToString();
            logEntry.RequestContentType =  request.ContentType;
            logEntry.RequestIpAddress = request.RemoteIpAddress;
            logEntry.RequestMethod = request.Method;
            logEntry.RequestRouteData = "";
            logEntry.RequestRouteTemplate = "";
            logEntry.RequestUri = request.Uri.AbsoluteUri;

            return this;
        }
开发者ID:barisakan,项目名称:WebApiTrial,代码行数:13,代码来源:WebApiLogger.cs


示例18: TryIsValidRequest

        private bool TryIsValidRequest(IOwinRequest request, out string requestAppId)
        {
            requestAppId = null;

            AuthenticationHeaderValue authHeader;
            if (!AuthenticationHeaderValue.TryParse(request.Headers["Authorization"], out authHeader) || authHeader.Scheme != "SOW")
            {
                return false;
            }

            var parameters = authHeader.Parameter.Split(':');
            if (parameters.Length != 3)
            {
                return false;
            }
            requestAppId = parameters[0];
            var requestSignature = parameters[1];
            var requestTimeStamp = parameters[2];

            var apiKey = _appKeyProvider.GetKey(requestAppId);
            if (apiKey == null)
            {
                return false;
            }

            // TODO check replay request

            // Compute hash
            var requestContent = string.Empty;
            var hash = ComputeHash(request);
            if (hash != null)
            {
                requestContent = Convert.ToBase64String(hash);
            }

            var requestMethod = request.Method;
            var requestUri = WebUtility.UrlEncode(request.Uri.ToString().ToLowerInvariant());
            var hmacData = string.Concat(requestAppId, requestMethod, requestUri, requestTimeStamp, requestContent);

            var secretKeyBytes = Convert.FromBase64String(apiKey);
            var signature = Encoding.UTF8.GetBytes(hmacData);

            using (var hmac = new HMACSHA256(secretKeyBytes))
            {
                var signatureBytes = hmac.ComputeHash(signature);
                var signatureString = Convert.ToBase64String(signatureBytes);
                return requestSignature.Equals(signatureString, StringComparison.Ordinal);
            }
        }
开发者ID:jamieide,项目名称:StacksOfWax,代码行数:49,代码来源:HmacAuthOwinMiddleware.cs


示例19: ClientCached

        private bool ClientCached(IOwinRequest request, DateTime contentModified)
        {
            string header = request.Headers["If-Modified-Since"];

            if (header != null)
            {
                DateTime isModifiedSince;
                if (DateTime.TryParse(header, out isModifiedSince))
                {
                    return isModifiedSince >= contentModified.AddSeconds(-1);
                }
            }

            return false;
        }
开发者ID:koblerkrisztian,项目名称:Knockout.Bootstrap.TemplateStore,代码行数:15,代码来源:TemplateStoreMiddleware.cs


示例20: SetRequestId

      private void SetRequestId(IOwinRequest request)
      {
         string requestId;

         string[] requestIds;
         if (request.Headers.TryGetValue(RequestIdHeaderName, out requestIds) && requestIds != null && requestIds.Length > 0)
         {
            requestId = requestIds[0];
         }
         else
         {
            requestId = Guid.NewGuid().ToString();
         }

         HttpContext.Current.Items[RequestIdHeaderName] = requestId;
      }
开发者ID:aloneguid,项目名称:logmagic,代码行数:16,代码来源:LogMagicMiddleware.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# IPAddress类代码示例发布时间:2022-05-24
下一篇:
C# IOwinContext类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap