本文整理汇总了C#中IHttpContext.GetRequestUrl方法的典型用法代码示例。如果您正苦于以下问题:C# IHttpContext.GetRequestUrl方法的具体用法?C# IHttpContext.GetRequestUrl怎么用?C# IHttpContext.GetRequestUrl使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IHttpContext
的用法示例。
在下文中一共展示了IHttpContext.GetRequestUrl方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Authorize
public override bool Authorize(IHttpContext ctx)
{
if (server.DefaultConfiguration.AnonymousUserAccessMode == AnonymousUserAccessMode.None && IsInvalidUser(ctx))
{
var requestUrl = ctx.GetRequestUrl();
if (NeverSecret.Urls.Contains(requestUrl, StringComparer.InvariantCultureIgnoreCase))
return true;
ctx.SetStatusToUnauthorized();
return false;
}
var httpRequest = ctx.Request;
if (server.DefaultConfiguration.AnonymousUserAccessMode == AnonymousUserAccessMode.Get &&
IsInvalidUser(ctx) &&
IsGetRequest(httpRequest.HttpMethod, httpRequest.Url.AbsolutePath) == false)
{
var requestUrl = ctx.GetRequestUrl();
if (NeverSecret.Urls.Contains(requestUrl, StringComparer.InvariantCultureIgnoreCase))
return true;
ctx.SetStatusToUnauthorized();
return false;
}
if (IsInvalidUser(ctx) == false)
CurrentOperationContext.Headers.Value[Constants.RavenAuthenticatedUser] = ctx.User.Identity.Name;
return true;
}
示例2: Authorize
public override bool Authorize(IHttpContext ctx)
{
if (server.DefaultConfiguration.AnonymousUserAccessMode == AnonymousUserAccessMode.None && IsInvalidUser(ctx))
{
var requestUrl = ctx.GetRequestUrl();
if (neverSecretUrls.Contains(requestUrl, StringComparer.InvariantCultureIgnoreCase))
return true;
ctx.SetStatusToUnauthorized();
return false;
}
var httpRequest = ctx.Request;
if (server.DefaultConfiguration.AnonymousUserAccessMode == AnonymousUserAccessMode.Get &&
IsInvalidUser(ctx) &&
IsGetRequest(httpRequest.HttpMethod, httpRequest.Url.AbsolutePath) == false)
{
var requestUrl = ctx.GetRequestUrl();
if (neverSecretUrls.Contains(requestUrl, StringComparer.InvariantCultureIgnoreCase))
return true;
ctx.SetStatusToUnauthorized();
return false;
}
return true;
}
示例3: Respond
public override void Respond(IHttpContext context)
{
var parameters = GetParametersFromPath(context.GetRequestUrl(), context.Request.QueryString);
var index = Database.IndexStorage.GetIndexInstance(parameters.IndexName);
if (index == null)
{
context.SetStatusToNotFound();
context.WriteJson(new { Error = "The index " + parameters.IndexName + " cannot be found" });
return;
}
var indexEtag = Database.GetIndexEtag(parameters.IndexName, null);
if (context.MatchEtag(indexEtag))
{
context.SetStatusToNotModified();
return;
}
var result = Database.ExecuteMoreLikeThisQuery(parameters, GetRequestTransaction(context), context.GetPageSize(Database.Configuration.MaxPageSize), context.Request.QueryString.GetValues("include"));
if (context.MatchEtag(result.Etag))
{
context.SetStatusToNotModified();
return;
}
context.Response.AddHeader("ETag", result.Etag.ToString());
context.WriteJson(result.Result);
}
示例4: Respond
public override void Respond(IHttpContext context)
{
var match = urlMatcher.Match(context.GetRequestUrl());
var index = match.Groups[1].Value;
switch (context.Request.HttpMethod)
{
case "HEAD":
if(Database.IndexDefinitionStorage.IndexNames.Contains(index, StringComparer.InvariantCultureIgnoreCase) == false)
context.SetStatusToNotFound();
break;
case "GET":
OnGet(context, index);
break;
case "PUT":
Put(context, index);
break;
case "RESET":
Database.ResetIndex(index);
context.WriteJson(new {Reset = index});
break;
case "DELETE":
context.SetStatusToDeleted();
Database.DeleteIndex(index);
break;
}
}
示例5: Respond
public override void Respond(IHttpContext context)
{
var match = urlMatcher.Match(context.GetRequestUrl());
var queue = match.Groups[1].Value;
switch (context.Request.HttpMethod)
{
case "GET":
context.WriteJson(Queues.Statistics(queue));
break;
case "POST":
var metadata = context.Request.Headers.FilterHeaders(isServerDocument: true);
var msgId = Queues.Enqueue(new IncomingMessage
{
Data = context.Request.InputStream.ReadData(),
Queue = queue,
Metadata = metadata,
TimeToLive = metadata.Property("Raven-Time-To-Live") != null
? TimeSpan.FromSeconds(metadata.Value<int>("Raven-Time-To-Live"))
: TimeSpan.FromMinutes(5)
});
context.WriteJson(new {MsgId = msgId});
break;
}
}
示例6: Respond
public override void Respond(IHttpContext context)
{
var match = urlMatcher.Match(context.GetRequestUrl());
var filename = match.Groups[1].Value;
var etag = context.GetEtag();
switch (context.Request.HttpMethod)
{
case "GET":
var attachmentAndHeaders = Database.GetStatic(filename);
if (attachmentAndHeaders == null)
{
context.SetStatusToNotFound();
return;
}
if (context.MatchEtag(attachmentAndHeaders.Etag))
{
context.SetStatusToNotModified();
return;
}
context.WriteData(attachmentAndHeaders.Data, attachmentAndHeaders.Metadata,
attachmentAndHeaders.Etag);
break;
case "PUT":
Database.PutStatic(filename, context.GetEtag(), context.Request.InputStream.ReadData(),
context.Request.Headers.FilterHeaders(isServerDocument:false));
context.SetStatusToCreated("/static/" + filename);
break;
case "DELETE":
Database.DeleteStatic(filename, etag);
context.SetStatusToDeleted();
break;
}
}
示例7: Authorize
public bool Authorize(IHttpContext context)
{
var requestUrl = context.GetRequestUrl();
if (NeverSecret.Urls.Contains(requestUrl))
return true;
//CORS pre-flight (ignore creds if using cors).
if (!String.IsNullOrEmpty(Settings.AccessControlAllowOrigin) && context.Request.HttpMethod == "OPTIONS")
{ return true; }
var oneTimeToken = context.Request.Headers["Single-Use-Auth-Token"];
if (string.IsNullOrEmpty(oneTimeToken) == false)
{
return AuthorizeUsingleUseAuthToken(context, oneTimeToken);
}
var authHeader = context.Request.Headers["Authorization"];
var hasApiKey = "True".Equals(context.Request.Headers["Has-Api-Key"], StringComparison.CurrentCultureIgnoreCase);
var hasOAuthTokenInCookie = context.Request.HasCookie("OAuth-Token");
if (hasApiKey || hasOAuthTokenInCookie ||
string.IsNullOrEmpty(authHeader) == false && authHeader.StartsWith("Bearer "))
{
return oAuthRequestAuthorizer.Authorize(context, hasApiKey, IgnoreDb.Urls.Contains(requestUrl));
}
return windowsRequestAuthorizer.Authorize(context, IgnoreDb.Urls.Contains(requestUrl));
}
示例8: Respond
public override void Respond(IHttpContext context)
{
var match = urlMatcher.Match(context.GetRequestUrl());
var index = match.Groups[1].Value;
var facetSetupDoc = context.GetFacetSetupDocFromHttpContext();
var indexQuery = context.GetIndexQueryFromHttpContext(Database.Configuration.MaxPageSize);
var jsonDocument = Database.Get(facetSetupDoc, null);
if(jsonDocument == null)
{
context.SetStatusToNotFound();
context.Write("Could not find facet document: " + facetSetupDoc);
return;
}
var etag = GetFacetsEtag(jsonDocument, index);
if(context.MatchEtag(etag))
{
context.SetStatusToNotModified();
return;
}
context.WriteETag(etag);
context.WriteJson(Database.ExecuteGetTermsQuery(index, indexQuery, facetSetupDoc));
}
示例9: Respond
public override void Respond(IHttpContext context)
{
var match = urlMatcher.Match(context.GetRequestUrl());
var index = match.Groups[1].Value;
var indexQuery = context.GetIndexQueryFromHttpContext(Database.Configuration.MaxPageSize);
var facetStart = context.GetFacetStartFromHttpContext();
var facetPageSize = context.GetFacetPageSizeFromHttpContext();
List<Facet> facets;
Etag etag;
if (TryGetFacets(context, index, out etag, out facets) == false)
return;
if (context.MatchEtag(etag))
{
context.SetStatusToNotModified();
return;
}
context.WriteETag(etag);
context.WriteJson(Database.ExecuteGetTermsQuery(index, indexQuery, facets, facetStart, facetPageSize));
}
示例10: Respond
/// <summary>
/// Responds the specified context.
/// </summary>
/// <param name="context">The context.</param>
public override void Respond(IHttpContext context)
{
var match = urlMatcher.Match(context.GetRequestUrl());
var index = match.Groups[1].Value;
var term = context.Request.QueryString["term"];
var field = context.Request.QueryString["field"];
StringDistanceTypes distanceTypes;
int numOfSuggestions;
float accuracy;
if (Enum.TryParse(context.Request.QueryString["distance"], true, out distanceTypes) == false)
distanceTypes =StringDistanceTypes.Default;
if (int.TryParse(context.Request.QueryString["max"], out numOfSuggestions) == false)
numOfSuggestions = 10;
if(float.TryParse(context.Request.QueryString["accuracy"], out accuracy) == false)
accuracy = 0.5f;
var query = new SuggestionQuery
{
Distance = distanceTypes,
Field = field,
MaxSuggestions = numOfSuggestions,
Term = term,
Accuracy = accuracy
};
var suggestionQueryResult = Database.ExecuteSuggestionQuery(index, query);
context.WriteJson(suggestionQueryResult);
}
示例11: Respond
public override void Respond(IHttpContext context)
{
var match = urlMatcher.Match(context.GetRequestUrl());
var userId = match.Groups[1].Value;
var docIds = context.Request.QueryString.GetValues("id");
var operation = context.Request.QueryString["operation"];
var transactionInformation = GetRequestTransaction(context);
if (docIds == null || string.IsNullOrEmpty(operation) || string.IsNullOrEmpty(userId))
{
context.SetStatusToBadRequest();
return;
}
// we don't want security to take hold when we are trying to ask about security
using (Database.DisableAllTriggersForCurrentThread())
{
var documents = docIds.Select(docId=>Database.GetDocumentMetadata(docId, transactionInformation)).ToArray();
var etag = CalculateEtag(documents, userId);
if (context.MatchEtag(etag))
{
context.SetStatusToNotModified();
return;
}
context.Response.AddHeader("ETag", etag.ToString());
context.WriteJson(GenerateAuthorizationResponse(documents, docIds, operation, userId));
}
}
示例12: Respond
public override void Respond(IHttpContext context)
{
if(notifiedAboutSilverlightBeingRequested == false)
{
lock (this)
{
if (notifiedAboutSilverlightBeingRequested == false &&
SilverlightRequestedAware != null)
SilverlightRequestedAware.SilverlightWasRequested(ResourceStore);
notifiedAboutSilverlightBeingRequested = true;
}
}
var match = urlMatcher.Match(context.GetRequestUrl());
var fileName = match.Groups[1].Value;
var paths = GetPaths(fileName);
var matchingPath = paths.FirstOrDefault(File.Exists);
if (matchingPath != null)
{
context.WriteFile(matchingPath);
return;
}
context.SetStatusToNotFound();
}
示例13: Respond
public override void Respond(IHttpContext context)
{
var match = urlMatcher.Match(context.GetRequestUrl());
var index = match.Groups[1].Value;
switch (context.Request.HttpMethod)
{
case "HEAD":
if(Database.IndexDefinitionStorage.IndexNames.Contains(index, StringComparer.InvariantCultureIgnoreCase) == false)
context.SetStatusToNotFound();
break;
case "GET":
OnGet(context, index);
break;
case "PUT":
Put(context, index);
break;
case "DELETE":
if(index.StartsWith("Raven/",StringComparison.InvariantCultureIgnoreCase))
{
context.SetStatusToForbidden();
context.WriteJson(new
{
Url = context.Request.RawUrl,
Error = "Builtin indexes cannot be deleted, attempt to delete index '" + index + "' was rejected"
});
return;
}
context.SetStatusToDeleted();
Database.DeleteIndex(index);
break;
}
}
示例14: Respond
public override void Respond(IHttpContext context)
{
Database.ExtensionsState.GetOrAdd("SilverlightUI.NotifiedAboutSilverlightBeingRequested", s =>
{
foreach (var silverlightRequestedAware in SilverlightRequestedAware)
{
silverlightRequestedAware.Value.SilverlightWasRequested(Database);
}
return true;
});
var match = urlMatcher.Match(context.GetRequestUrl());
var fileName = match.Groups[1].Value;
var paths = GetPaths(fileName, Database.Configuration.WebDir);
var matchingPath = paths.FirstOrDefault(path =>
{
try
{
return File.Exists(path);
}
catch (Exception)
{
return false;
}
});
if (matchingPath != null)
{
context.WriteFile(matchingPath);
return;
}
context.WriteEmbeddedFile(Settings.WebDir, "Raven.Studio.xap");
}
示例15: Respond
public override void Respond(IHttpContext context)
{
var op = context.Request.QueryString["op"] == "from" ? "from" : "to";
var match = urlMatcher.Match(context.GetRequestUrl());
var docId = Uri.UnescapeDataString(match.Groups[1].Value);
int totalCountReferencing = -1;
List<string> results = null;
Database.TransactionalStorage.Batch(accessor =>
{
totalCountReferencing = accessor.Indexing.GetCountOfDocumentsReferencing(docId);
var documentsReferencing =
op == "from"
? accessor.Indexing.GetDocumentsReferencesFrom(docId)
: accessor.Indexing.GetDocumentsReferencing(docId);
results =
documentsReferencing
.Skip(context.GetStart())
.Take(context.GetPageSize(Database.Configuration.MaxPageSize))
.ToList();
});
context.WriteJson(new
{
TotalCountReferencing = totalCountReferencing,
Results = results
});
}