本文整理汇总了C#中Microsoft.AspNet.Http.HttpRequest类的典型用法代码示例。如果您正苦于以下问题:C# HttpRequest类的具体用法?C# HttpRequest怎么用?C# HttpRequest使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
HttpRequest类属于Microsoft.AspNet.Http命名空间,在下文中一共展示了HttpRequest类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateValueProviderAsync
private static async Task<IValueProvider> CreateValueProviderAsync(HttpRequest request)
{
return new FormValueProvider(
BindingSource.Form,
await request.ReadFormAsync(),
CultureInfo.CurrentCulture);
}
示例2: TryGetApiKey
private static bool TryGetApiKey(HttpRequest request, out string apiKey)
{
StringValues headerValue;
if (request.Headers.TryGetValue("Authorization", out headerValue))
{
AuthenticationHeaderValue authHeaderValue;
if (AuthenticationHeaderValue.TryParse(headerValue, out authHeaderValue))
{
apiKey = authHeaderValue.Parameter;
return true;
}
}
if (request.Headers.TryGetValue("X-Octopus-ApiKey", out headerValue))
{
apiKey = headerValue;
return true;
}
if (request.Headers.TryGetValue("X-NuGet-ApiKey", out headerValue))
{
apiKey = headerValue;
return true;
}
if (request.Query.ContainsKey("apikey"))
{
apiKey = request.Query["apikey"];
return true;
}
apiKey = null;
return false;
}
示例3: CreateValueProviderAsync
private static async Task<IValueProvider> CreateValueProviderAsync(HttpRequest request)
{
return new JQueryFormValueProvider(
BindingSource.Form,
await GetValueCollectionAsync(request),
CultureInfo.CurrentCulture);
}
示例4: ApplyQueryOptions
public virtual object ApplyQueryOptions(object value, HttpRequest request, ActionDescriptor descriptor)
{
var elementClrType = TypeHelper.GetImplementedIEnumerableType(value.GetType());
var model = request.ODataProperties().Model;
if (model == null)
{
throw Error.InvalidOperation(SRResources.QueryGetModelMustNotReturnNull);
}
var queryContext = new ODataQueryContext(
model,
elementClrType,
request.ODataProperties().Path);
var queryOptions = new ODataQueryOptions(queryContext, request);
var enumerable = value as IEnumerable;
if (enumerable == null)
{
// response is single entity.
return value;
}
// response is a collection.
var query = (value as IQueryable) ?? enumerable.AsQueryable();
return queryOptions.ApplyTo(query,
new ODataQuerySettings
{
HandleNullPropagation = HandleNullPropagationOption.True
});
}
示例5: Log
/*
* Very simple logger that logs to the VS Debug output window. Requires the debugger to be attached to work!
*/
public void Log(HttpRequest request, Exception ex)
{
/*
* Simplification due to time restrictions.
*/
Log(ex);
}
示例6: Combine
public static string Combine(HttpRequest request, string path, params Descriptor[] descriptors)
{
StringBuilder result = new StringBuilder();
foreach (Descriptor descriptor in descriptors)
{
if (!descriptor.Skip)
{
string value = descriptor.TakeFromUrl ? request.Query[descriptor.Name] : descriptor.Value;
if (!string.IsNullOrEmpty(value))
result.AppendFormat("{0}{1}={2}", result.Length == 0 ? '?' : '&', descriptor.Name, value);
}
}
foreach (KeyValuePair<string, string[]> keyValuePair in request.Query)
{
if (!descriptors.Any(d => d.Name == keyValuePair.Key))
{
string value = request.Query[keyValuePair.Key];
if (!string.IsNullOrEmpty(value))
result.AppendFormat("{0}{1}={2}", result.Length == 0 ? '?' : '&', keyValuePair.Key, value);
}
}
result.Insert(0, string.IsNullOrEmpty(path) ? request.Path.ToString() : path);
return result.ToString();
}
示例7: ODataQueryOptions
/// <summary>
/// Initializes a new instance of the <see cref="ODataQueryOptions"/> class based on the incoming request and some metadata information from
/// the <see cref="ODataQueryContext"/>.
/// </summary>
/// <param name="context">The <see cref="ODataQueryContext"/> which contains the <see cref="IEdmModel"/> and some type information.</param>
/// <param name="request">The incoming request message.</param>
public ODataQueryOptions(ODataQueryContext context, HttpRequest request)
{
if (context == null)
{
throw Error.ArgumentNull("context");
}
if (request == null)
{
throw Error.ArgumentNull("request");
}
_assemblyProvider = request.AssemblyProvider();
Context = context;
Request = request;
RawValues = new ODataRawQueryOptions();
var queryOptionDict = request.Query.ToDictionary(p => p.Key, p => p.Value.FirstOrDefault());
_queryOptionParser = new ODataQueryOptionParser(
context.Model,
context.ElementType,
context.NavigationSource,
queryOptionDict);
BuildQueryOptions(queryOptionDict);
}
示例8: ParseAuthenticationHeader
private static bool ParseAuthenticationHeader(MgHttpRequestParam param, HttpRequest request)
{
//This method decodes and extracts the username and password from the http authentication
//header (if it exists) and packs the values into the MgHttpRequestParam object if they
//exist
String auth = request.Headers["authorization"];
if (auth != null && auth.Length > 6)
{
auth = auth.Substring(6);
byte[] decoded = Convert.FromBase64String(auth);
String decodedStr = Encoding.UTF8.GetString(decoded);
String[] decodedTokens = decodedStr.Split(':');
if (decodedTokens.Length == 1 || decodedTokens.Length == 2)
{
String username = decodedTokens[0];
String password = "";
if (decodedTokens.Length == 2)
password = decodedTokens[1];
param.AddParameter("USERNAME", username);
param.AddParameter("PASSWORD", password);
return true;
}
}
return false;
}
示例9: OnReceived
protected override async Task OnReceived(HttpRequest request, string connectionId, string data) {
var identity = request.HttpContext.User.Identity;
var status = identity.IsAuthenticated ? "authenticated" : "unauthenticated";
var name = identity.IsAuthenticated ? identity.Name : "client";
await Connection.Send(connectionId, $"Received an {status} message from {name}: {data}");
}
示例10: GetBasicAuth
public BasicAuthIdentity GetBasicAuth(HttpRequest request)
{
BasicAuthIdentity identity = null;
var headerValue = request.Headers["Authorization"];
if (!String.IsNullOrEmpty(headerValue))
{
var headerValues = headerValue.Split(' ');
var scheme = headerValues[0];
if (string.Compare(scheme, "Basic", true) == 0)
{
var encodedUsernameAndPassword = headerValues[1];
var usernameAndPassword = Encoding.UTF8.GetString(Convert.FromBase64String(encodedUsernameAndPassword));
if (usernameAndPassword != null && usernameAndPassword != ":")
{
var tokens = usernameAndPassword.Split(':');
switch (tokens.Length)
{
case 2:
identity = new BasicAuthIdentity(tokens[0], tokens[1]);
break;
case 1:
identity = new BasicAuthIdentity(tokens[0], null);
break;
default:
identity = null;
break;
}
}
}
}
return identity;
}
示例11: RequestingSwaggerUi
private bool RequestingSwaggerUi(HttpRequest request)
{
if (request.Method != "GET") return false;
var routeValues = _requestMatcher.Match(request.Path);
return (routeValues != null);
}
示例12: RequestingSwaggerUi
private bool RequestingSwaggerUi(HttpRequest request)
{
if (request.Method != "GET") return false;
var routeValues = _requestMatcher.Match(request.Path.ToUriComponent().Trim('/'));
return (routeValues != null);
}
示例13: OnDisconnected
protected override Task OnDisconnected(HttpRequest request, string connectionId, bool stopCalled)
{
string ignored;
_users.TryRemove(connectionId, out ignored);
string suffix = stopCalled ? "cleanly" : "uncleanly";
return Connection.Broadcast(DateTime.Now + ": " + GetUser(connectionId) + " disconnected " + suffix);
}
示例14: RequestPrefersReturnNoContent
internal static bool RequestPrefersReturnNoContent(HttpRequest request)
{
string[] preferences = null;
if (request.Headers.TryGetValue(PreferHeaderName, out preferences))
{
return preferences.Contains(ReturnNoContentHeaderValue);
}
return false;
}
示例15: OrderedFileSet
public OrderedFileSet(IEnumerable<IWebFile> files,
FileSystemHelper fileSystemHelper,
HttpRequest request,
PreProcessPipeline defaultPipeline)
{
_files = files;
_defaultPipeline = defaultPipeline;
_fileSystemHelper = fileSystemHelper;
_request = request;
}