本文整理汇总了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;
}
示例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;
}
示例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;
}
示例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);
}
示例5: Inbound
private void Inbound(IOwinRequest request, string beforeValue)
{
if (beforeValue != null)
{
RouteParams.Set(request.Environment, inRouteParam, beforeValue);
}
}
示例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];
}
示例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;
}
示例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");
}
示例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"));
}
示例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);
}
示例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;
}
示例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));
}
示例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;
}
}
}
示例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();
}
示例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();
}