本文整理汇总了C#中Microsoft.AspNet.Http.HttpContext.RespondWith方法的典型用法代码示例。如果您正苦于以下问题:C# HttpContext.RespondWith方法的具体用法?C# HttpContext.RespondWith怎么用?C# HttpContext.RespondWith使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.AspNet.Http.HttpContext
的用法示例。
在下文中一共展示了HttpContext.RespondWith方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Invoke
public async Task Invoke(HttpContext context, IDictionary<string, string> parameters)
{
var types = parameters.ParseEnumerable("types").ToArray();
if (types.Length == 0)
{
await context.RespondWith(
new MissingParameterProblem("types")
.EnableCaching());
return;
}
var list = await _store.RetrieveByType(types);
await context.RespondWith(new RawJson(list.ToJsonArray()));
}
示例2: Invoke
public async Task Invoke(HttpContext context, IDictionary<string, string> parameters)
{
if (context.Request.Method.Equals("OPTIONS", StringComparison.OrdinalIgnoreCase))
{
// CORS - this is super basic...
var headers = context.Response.Headers;
headers["Access-Control-Allow-Origin"] = "*";
headers["Access-Control-Allow-Methods"] = "POST";
headers["Access-Control-Allow-Headers"] = context.Request.Headers["Access-Control-Request-Headers"];
context.Response.StatusCode = 200;
await context.Response.WriteAsync("");
return;
}
IEnumerable<Message> messages = null;
if (context.Request.Method.Equals("POST", StringComparison.OrdinalIgnoreCase))
{
try
{
messages = ReadMessage(context.Request).ToArray();
foreach (var message in messages)
{
_messageServerBus.SendMessage(message);
}
}
catch (JsonReaderException exception)
{
await context.RespondWith(new InvalidJsonProblem(exception).EnableCors());
return;
}
catch (Exception exception)
{
await context.RespondWith(new ExceptionProblem(exception).EnableCors());
return;
}
await context.RespondWith(
new HttpStatusResponse(HttpStatusCode.Accepted,
"Accepted: " + string.Join(", ", messages.Select(m => m.Id.ToString("N"))))
.EnableCors());
}
else
{
await context.RespondWith(
new InvalidMethodProblem(context.Request.Method, "POST")
.EnableCors());
}
}
示例3: Invoke
public async Task Invoke(HttpContext context, IDictionary<string, string> parameters)
{
var filters = GetFilters(parameters);
IEnumerable<string> list;
var types = parameters.ParseEnumerable("types").ToArray();
if (types.Length > 0)
{
list = await _requests.Query(filters, types);
}
else
{
list = await _requests.Query(filters);
}
await context.RespondWith(
new RawJson(list.ToJsonArray()));
}
示例4: Invoke
public async Task Invoke(HttpContext context, IDictionary<string, string> parameters)
{
var resourceOptions = _resourceOptionsProvider.BuildInstance();
var json = [email protected]"{{
""resources"":
{{
""browserAgentScriptTemplate"" : ""{resourceOptions.BrowserAgentScriptTemplate}"",
""hudScriptTemplate"" : ""{resourceOptions.HudScriptTemplate}"",
""messageIngressTemplate"" : ""{resourceOptions.MessageIngressTemplate}"",
""metadataTemplate"" : ""{resourceOptions.MetadataTemplate}"",
""contextTemplate"" : ""{resourceOptions.ContextTemplate}"",
""clientScriptTemplate"" : ""{resourceOptions.ClientScriptTemplate}""
}}
}}";
await context.RespondWith(
new RawJson(json)
.AsFile("glimpse.json"));
}
示例5: Invoke
public async Task Invoke(HttpContext context, IDictionary<string, string> parameters)
{
var metadata = GetMetadata();
await context.RespondWith(new Json(metadata));
}