本文整理汇总了C#中System.Net.Http.Headers.HttpRequestHeaders类的典型用法代码示例。如果您正苦于以下问题:C# HttpRequestHeaders类的具体用法?C# HttpRequestHeaders怎么用?C# HttpRequestHeaders使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
HttpRequestHeaders类属于System.Net.Http.Headers命名空间,在下文中一共展示了HttpRequestHeaders类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: BuildClaimsPrincipal
private async Task<ClaimsPrincipal> BuildClaimsPrincipal(HttpRequestHeaders headers)
{
string credentials;
try
{
var token = Convert.FromBase64String(headers.Authorization.Parameter);
credentials = Encoding.UTF8.GetString(token);
}
catch (FormatException)
{
return null;
}
catch (ArgumentException)
{
return null;
}
var parts = credentials.Split(':');
if (parts.Length != 2)
return null;
var userId = parts[0].Trim();
var password = parts[1].Trim();
if (! await _validateCredentials(userId, password))
return null;
var claims = new[] {new Claim(ClaimTypes.Name, userId)};
var claimsIdentities = new[] {new ClaimsIdentity(claims, Scheme)};
return new ClaimsPrincipal(claimsIdentities);
}
开发者ID:kazheko,项目名称:examples,代码行数:32,代码来源:BasicAuthenticationHandler.cs
示例2: GetFromRequestHeaders
public static ApiCredentials GetFromRequestHeaders(HttpRequestHeaders requestHeaders)
{
//this could/should be another interface for testing purposes
var authenticationHeader = requestHeaders.Authorization;
if (authenticationHeader.Scheme != Configuration.AuthenticationScheme)
{
return null;
}
if (requestHeaders.Authorization == null || requestHeaders.Authorization.Parameter == null
|| !requestHeaders.Authorization.Parameter.Contains(":"))
{
return null;
}
var apiKey = requestHeaders.Authorization.Parameter.Split(':')[0];
if (apiKey == null)
{
return null;
}
var decodedBytes = Convert.FromBase64String(authenticationHeader.Parameter);
var signature = Encoding.UTF8.GetString(decodedBytes);
return new ApiCredentials()
{
Signature = signature,
ApiKey = apiKey
};
}
开发者ID:rbanks54,项目名称:HMAC.Sample,代码行数:28,代码来源:ApiCredentials.cs
示例3: CopyTo
internal static void CopyTo(this HttpRequestHeaders from, HttpRequestHeaders to)
{
foreach (var header in from)
{
to.TryAddWithoutValidation(header.Key, header.Value);
}
}
开发者ID:D3-LucaPiombino,项目名称:WebAPI-Proxy,代码行数:7,代码来源:HeadersExtensions.cs
示例4: GetCookie
public static string GetCookie(HttpRequestHeaders headers, string name)
{
var cookies = headers.GetCookies(name).FirstOrDefault();
if (cookies == null) return null;
var cookie = cookies.Cookies.SingleOrDefault(x => x.Name == name);
return cookie == null ? null : cookie.Value;
}
开发者ID:rocky0904,项目名称:mozu-dotnet-webtoolkit,代码行数:7,代码来源:FilterUtils.cs
示例5: Populate
internal void Populate(HttpRequestHeaders headers)
{
if (this.Range != null)
{
headers.Range = new RangeHeaderValue(this.Range[0], this.Range[1]);
}
if (this.ModifiedSinceConstraint.HasValue)
{
headers.IfModifiedSince = new DateTimeOffset(this.ModifiedSinceConstraint.Value);
}
if (this.UnmodifiedSinceConstraint.HasValue)
{
headers.IfUnmodifiedSince = new DateTimeOffset(this.UnmodifiedSinceConstraint.Value);
}
if (this._matchingETagConstraints.Count > 0)
{
foreach (string temp in this._matchingETagConstraints)
headers.IfMatch.Add(new EntityTagHeaderValue(temp));
}
if (this._nonmatchingEtagConstraints.Count > 0)
{
foreach (string temp in this._nonmatchingEtagConstraints)
headers.IfMatch.Add(new EntityTagHeaderValue(temp));
}
}
开发者ID:zhongleiyang,项目名称:OssSDK-.net-4.5,代码行数:25,代码来源:GetObjectRequest.cs
示例6: CanonicalizedHeaders
internal static string CanonicalizedHeaders(HttpRequestHeaders headers)
{
var canonicalizedString = new CanonicalizedString(string.Empty);
var keyList =
headers.Where(h => h.Key.StartsWith("x-ms-", StringComparison.OrdinalIgnoreCase)).Select(header => header.Key).ToList();
keyList.Sort();
foreach (string str2 in keyList)
{
var builder = new StringBuilder(str2);
string str3 = ":";
foreach (string str4 in GetHeaderValues(headers, str2))
{
string str5 = str4.Replace("\r\n", string.Empty);
builder.Append(str3);
builder.Append(str5);
str3 = ",";
}
canonicalizedString.AppendCanonicalizedElement(builder.ToString());
}
return canonicalizedString.Value.TrimEnd('\n').TrimStart('\n');
}
开发者ID:wadewegner,项目名称:TechEd_NZAU,代码行数:25,代码来源:CredentialExtensions.cs
示例7: Populate
internal void Populate(HttpRequestHeaders headers)
{
if (this.CacheControl != null)
{
headers.Add("response-cache-control", this.CacheControl);
}
if (this.ContentDisposition != null)
{
headers.Add("response-content-disposition", this.ContentDisposition);
}
if (this.ContentEncoding != null)
{
headers.Add("response-content-encoding", this.ContentEncoding);
}
if (this.ContentLanguage != null)
{
headers.Add("response-content-language", this.ContentLanguage);
}
if (this.ContentType != null)
{
headers.Add("response-content-type", this.ContentType);
}
if (this.Expires != null)
{
headers.Add("response-expires", this.Expires);
}
}
开发者ID:zhongleiyang,项目名称:win8SDK,代码行数:27,代码来源:ResponseHeaderOverrides.cs
示例8: Authentication
/// <summary>
/// Authorization request header from client.
/// </summary>
/// <param name="header">header from client</param>
/// <returns>-401/-403/{userId}</returns>
public static long Authentication(HttpRequestHeaders header)
{
string authorization = header.GetValues("Authorization").FirstOrDefault();
if (authorization == null)
{
return -401;
}
using (var db = new CF_FamsamEntities())
{
string token = authorization.Split(null)[1];
Session session = db.Session.Find(token);
Debug.WriteLine("____________________________" + session.token);
if (session == null) return -403;
if (session.expired < DateTime.Now)
{
Debug.WriteLine("____________________________ session mili:" + session.expired.Millisecond);
Debug.WriteLine("____________________________ now mili:" + DateTime.Now.Millisecond);
//session expired
db.Session.Remove(session);
db.SaveChanges();
return -403;
}
else
{
return session.User.id;
}
}
}
开发者ID:sivarajankumar,项目名称:famsam,代码行数:38,代码来源:UserDAO.cs
示例9: _GetCanonicalizedHeaders
private string _GetCanonicalizedHeaders(HttpRequestHeaders headers)
{
var orderedHeaders = headers.OrderBy(x => x.Key);
var headersWithAggregatedValues = orderedHeaders.Where(x => x.Key.StartsWith("x-ms")).Select(x => x.Key.ToLowerInvariant() + ":" + headers.GetValues(x.Key).Aggregate((x1, x2) => x1 + "," + x2));
var canonicalHeader = headersWithAggregatedValues.Aggregate((x1, x2) => x1 + "\n" + x2) + "\n";
return canonicalHeader;
}
开发者ID:awithy,项目名称:AzureStorage,代码行数:7,代码来源:AuthorizationHeaderBuilder.cs
示例10: HttpRequestMessage
/// <summary>
/// Initializes a new instance of the <see cref="HttpRequestMessage" /> class
/// with an HTTP method and a request System.Uri.
/// </summary>
/// <param name="method">The HTTP method.</param>
/// <param name="requestUri">The System.Uri to request.</param>
public HttpRequestMessage(HttpMethod method, Uri requestUri)
{
RequestUri = requestUri;
Properties = new Dictionary<string, object>();
Version = new Version("1.1");
Method = method;
Headers = new HttpRequestHeaders(new WebHeaderCollection());
}
开发者ID:modulexcite,项目名称:SharpGIS.HttpClient.WP,代码行数:14,代码来源:HttpRequestMessage.cs
示例11: GetValueStorage
public string GetValueStorage(HttpRequestHeaders context, string key)
{
var cookie = context.GetCookies(key).FirstOrDefault();
if (cookie != null)
return cookie[key].Value;
return null;
}
开发者ID:vitek0585,项目名称:FashionStore,代码行数:9,代码来源:CookieConsumer.cs
示例12: IsHeaderContainToken
public static bool IsHeaderContainToken(HttpRequestHeaders header)
{
if (header.Contains(Constants.AccessTokenKey))
{
return true;
}
return false;
}
开发者ID:nguyenminhthu,项目名称:TeleConsult,代码行数:9,代码来源:AccessTokenChecker.cs
示例13: CanonicalizeHttpHeaders
/// <summary>
/// Canonicalizes the HTTP headers.
/// </summary>
/// <param name="method">The HTTP method for the request.</param>
/// <param name="requestHeaders">The request headers.</param>
/// <param name="contentHeaders">The content headers.</param>
/// <returns>A string representation of the HTTP headers.</returns>
private static string CanonicalizeHttpHeaders(
HttpMethod method,
HttpRequestHeaders requestHeaders,
HttpContentHeaders contentHeaders)
{
long? contentLength = contentHeaders != null ? contentHeaders.ContentLength : null;
return CanonicalizeHttpHeaders(method, contentLength, requestHeaders, contentHeaders);
}
开发者ID:blowdart,项目名称:Idunno.WebApi.SharedKeyAuth,代码行数:16,代码来源:SharedKeySignature.cs
示例14: ReadAuthenticationContent
protected bool ReadAuthenticationContent(HttpRequestHeaders authenticationContent, string key, out string value)
{
value = string.Empty;
var content = authenticationContent.FirstOrDefault(pair => pair.Key == key);
if (content.Value == null || content.Value.Count() != 1)
return false;
value = content.Value.First();
return true;
}
开发者ID:basharathussain,项目名称:doctors_app,代码行数:9,代码来源:CustomAuthorize.cs
示例15: Build
public string Build(string verb, string content, StorageUri uri, AzureStorageAccountInfo accountInfo, HttpRequestHeaders headers, string contentType)
{
var ifMatch = "";
var md5 = "";
var canonicalizedHeaderString = _GetCanonicalizedHeaders(headers);
var canonResource = _GetCanonicalizedResource(new Uri(uri.ToUriString()), accountInfo.Account);
var authorizationHeader = _GetAuthorizationHeader(verb, content, ifMatch, canonicalizedHeaderString, canonResource, md5, accountInfo, contentType);
return authorizationHeader;
}
开发者ID:awithy,项目名称:AzureStorage,代码行数:9,代码来源:AuthorizationHeaderBuilder.cs
示例16: AuthenticateUser
public static bool AuthenticateUser(HttpRequestHeaders HttpHeaders)
{
if (HttpHeaders.Contains(HttpRequestHeaderName))
{
var authHeader = HttpHeaders.GetValues(HttpRequestHeaderName).First();
return _authenticateHeaderValue(authHeader);
}
return false;
}
开发者ID:jerroydmoore,项目名称:Cerberus,代码行数:9,代码来源:BasicAuth.cs
示例17: GetCookieValue
private static string GetCookieValue(IAbpAntiForgeryManager manager, HttpRequestHeaders headers)
{
var cookie = headers.GetCookies(manager.Configuration.TokenCookieName).LastOrDefault();
if (cookie == null)
{
return null;
}
return cookie[manager.Configuration.TokenCookieName].Value;
}
开发者ID:vytautask,项目名称:aspnetboilerplate,代码行数:10,代码来源:AbpAntiForgeryManagerWebApiExtensions.cs
示例18: CopyTo
public static void CopyTo(this HttpRequestHeaders fromHeaders, HttpRequestHeaders toHeaders)
{
Contract.Assert(fromHeaders != null, "fromHeaders cannot be null.");
Contract.Assert(toHeaders != null, "toHeaders cannot be null.");
foreach (KeyValuePair<string, IEnumerable<string>> header in fromHeaders)
{
toHeaders.TryAddWithoutValidation(header.Key, header.Value);
}
}
开发者ID:haoduotnt,项目名称:aspnetwebstack,代码行数:10,代码来源:HttpHeaderExtensions.cs
示例19: GetHeaderValue
private static string GetHeaderValue(HttpRequestHeaders headers, string headerName)
{
var values = GetHeaderValues(headers, headerName);
if (values.Any())
{
// TODO: Test this to make sure it works in all cases, like null value of header key that exists
return values.Take(1).FirstOrDefault();
}
return string.Empty;
}
开发者ID:divyang4481,项目名称:STS,代码行数:11,代码来源:HttpRequestMessageExtensions.cs
示例20: GetHeaderValues
private static IEnumerable<string> GetHeaderValues(HttpRequestHeaders headers, string headerName)
{
var header = headers.Where(
fx => fx.Key.Equals(headerName, StringComparison.CurrentCultureIgnoreCase)).FirstOrDefault();
if ( header.Key != null && header.Value != null )
{
return header.Value;
}
return new List<string>();
}
开发者ID:divyang4481,项目名称:STS,代码行数:11,代码来源:HttpRequestMessageExtensions.cs
注:本文中的System.Net.Http.Headers.HttpRequestHeaders类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论