本文整理汇总了C#中IOwinContext类的典型用法代码示例。如果您正苦于以下问题:C# IOwinContext类的具体用法?C# IOwinContext怎么用?C# IOwinContext使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
IOwinContext类属于命名空间,在下文中一共展示了IOwinContext类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: Invoke
public override async Task Invoke(IOwinContext context)
{
Func<IDictionary<string, object>, object> func;
if (_config.TryGetValue(context.Request.Path, out func))
{
try
{
var result = func(context.Request.ToDatabag()) ?? new { };
context.Response.Write(result.ToJsonString());
await Next.Invoke(context);
}
catch (Exception e)
{
context.Response.StatusCode = (int)HttpStatusCode.InternalServerError;
var jsonString = new { exception = e.ToString() }.ToJsonString();
context.Response.Write(jsonString);
}
}
else
{
// Returns 404
context.Response.StatusCode = (int)HttpStatusCode.NotFound;
}
}
开发者ID:art2003,项目名称:Medidata.Cloud.Thermometer,代码行数:25,代码来源:ActionRouteMiddleware.cs
示例2: Invoke
public override Task Invoke(IOwinContext context)
{
string header;
switch (_xFrameOptions)
{
case XFrameOptions.Deny:
header = XFrameOptionsConstants.Deny;
break;
case XFrameOptions.Sameorigin:
header = XFrameOptionsConstants.Sameorigin;
break;
case XFrameOptions.AllowFrom:
header = string.Format(XFrameOptionsConstants.AllowFrom, _uri);
break;
default:
header = XFrameOptionsConstants.Sameorigin;
break;
}
var headers = context.Response.Headers;
if (headers.ContainsKey(XFrameOptionsConstants.Header))
{
headers[XFrameOptionsConstants.Header] = header;
}
else
{
headers.Append(XFrameOptionsConstants.Header, header);
}
return Next.Invoke(context);
}
开发者ID:ilich,项目名称:OnDotNet.Owin.Shield,代码行数:34,代码来源:FrameguardMiddleware.cs
示例3: Invoke
public override Task Invoke(IOwinContext context)
{
var dispatcher = _routes.FindDispatcher(context.Request.Path.Value);
if (dispatcher == null)
{
return Next.Invoke(context);
}
foreach (var filter in _authorizationFilters)
{
if (!filter.Authorize(context.Environment))
{
context.Response.StatusCode = (int) HttpStatusCode.Unauthorized;
return Task.FromResult(false);
}
}
var dispatcherContext = new RequestDispatcherContext(
_appPath,
_storage,
context.Environment,
dispatcher.Item2);
return dispatcher.Item1.Dispatch(dispatcherContext);
}
开发者ID:GitHuang,项目名称:Hangfire,代码行数:26,代码来源:DashboardMiddleware.cs
示例4: InvokeNext
private async Task InvokeNext(IOwinContext context)
{
if (Next != null)
{
await Next.Invoke(context);
}
}
开发者ID:estei,项目名称:Owin.Hsts,代码行数:7,代码来源:HstsMiddleware.cs
示例5: Apply
public static void Apply(this CommandResult commandResult, IOwinContext context)
{
if (commandResult == null)
{
throw new ArgumentNullException("commandResult");
}
if (context == null)
{
throw new ArgumentNullException("context");
}
context.Response.ContentType = commandResult.ContentType;
context.Response.StatusCode = (int)commandResult.HttpStatusCode;
if (commandResult.Location != null)
{
context.Response.Headers["Location"] = commandResult.Location.OriginalString;
}
if (commandResult.Content != null)
{
using (var writer = new StreamWriter(context.Response.Body, Encoding.UTF8, 1024, true))
{
writer.Write(commandResult.Content);
}
}
}
开发者ID:Raschmann,项目名称:authservices,代码行数:28,代码来源:CommandResultExtensions.cs
示例6: Invoke
public async override Task Invoke(IOwinContext context)
{
context.Set(OriginalStreamKey, context.Response.Body);
context.Response.Body = new StreamWrapper(context.Response.Body, InspectStatusCode, context);
await Next.Invoke(context);
StatusCodeAction action;
string link;
int statusCode = context.Response.StatusCode;
bool? replace = context.Get<bool?>(ReplacementKey);
if (!replace.HasValue)
{
// Never evaluated, no response sent yet.
if (options.StatusCodeActions.TryGetValue(statusCode, out action)
&& links.TryGetValue(statusCode, out link)
&& action != StatusCodeAction.Ignore)
{
await SendKitten(context, link);
}
}
else if (replace.Value == true)
{
if (links.TryGetValue(statusCode, out link))
{
await SendKitten(context, link);
}
}
}
开发者ID:Tratcher,项目名称:Owin-Dogfood,代码行数:28,代码来源:KittenStatusCodeMiddleware.cs
示例7: Invoke
async Task Invoke(IOwinContext context)
{
string error = null;
try
{
switch (context.Request.Method)
{
case "GET":
await InvokeGET(context);
break;
case "POST":
await InvokePOST(context);
break;
default:
await context.Response.WriteAsync("NotFound");
context.Response.StatusCode = (int)HttpStatusCode.NotFound;
break;
}
}
catch (Exception e)
{
error = e.Message;
}
if (error != null)
{
context.Response.StatusCode = (int)HttpStatusCode.InternalServerError;
}
}
开发者ID:jinujoseph,项目名称:NuGet.Services.Metadata,代码行数:30,代码来源:Startup.cs
示例8: InvokeGET
async Task InvokeGET(IOwinContext context)
{
switch (context.Request.Path.Value)
{
case "/":
{
context.Response.Write("OK");
context.Response.StatusCode = (int)HttpStatusCode.OK;
break;
}
case "/claims":
{
JArray result = new JArray();
foreach (Claim claim in ClaimsPrincipal.Current.Claims)
{
JObject obj = new JObject();
obj.Add("type", claim.Type);
obj.Add("value", claim.Value);
result.Add(obj);
}
await context.Response.WriteAsync(result.ToString());
context.Response.ContentType = "application/json";
context.Response.StatusCode = (int)HttpStatusCode.OK;
break;
}
default:
{
await context.Response.WriteAsync("NotFound");
context.Response.StatusCode = (int)HttpStatusCode.NotFound;
break;
}
}
}
开发者ID:jinujoseph,项目名称:NuGet.Services.Metadata,代码行数:34,代码来源:Startup.cs
示例9:
void IOwinContextCleaner.Clean(IOwinContext context)
{
if (context.Environment.ContainsKey(QOMVC_PLUGIN_KEY))
context.Environment.Remove(QOMVC_PLUGIN_KEY);
if (context.Environment.ContainsKey(QOMVC_PATH_KEY))
context.Environment.Remove(QOMVC_PATH_KEY);
}
开发者ID:aaasoft,项目名称:Quick.OwinMVC,代码行数:7,代码来源:AbstractPluginPathMiddleware.cs
示例10: ProcessRequest
/// <summary>
/// Processes the HTTP request for controllers.
/// </summary>
/// <param name="containerProvider">The DI container provider.</param>
/// <param name="context">The context.</param>
/// <returns></returns>
public Task ProcessRequest(IDIContainerProvider containerProvider, IOwinContext context)
{
var result = _controllersProcessor.ProcessControllers(containerProvider, context);
switch (result)
{
case ControllersProcessorResult.Ok:
return _pageProcessor.ProcessPage(containerProvider, context);
case ControllersProcessorResult.Http401:
context.Response.StatusCode = 401;
_redirector.SetLoginReturnUrlFromCurrentUri();
break;
case ControllersProcessorResult.Http403:
context.Response.StatusCode = 403;
break;
case ControllersProcessorResult.Http404:
context.Response.StatusCode = 404;
break;
}
return Task.Delay(0);
}
开发者ID:i4004,项目名称:Simplify.Web,代码行数:31,代码来源:ControllersRequestHandler.cs
示例11: Invoke
public Task Invoke(IOwinContext context, Func<Task> next)
{
var content = new StringBuilder();
content.Append("The Urchin Server failed to initialize correctly on ");
content.Append(Environment.MachineName);
content.Append(".\n");
content.Append("There is a configuration error in Urchin, or a failure in something that Urchin depends on.\n\n");
content.Append("Check the error log for more detailed information.\n\n");
if (_exception != null)
{
content.Append("The exception that was caught was ");
content.Append(_exception.GetType().FullName);
content.Append("\n");
content.Append(_exception.Message);
content.Append("\n");
if (_exception.StackTrace != null)
{
content.Append(_exception.StackTrace);
content.Append("\n");
}
var inner = _exception.InnerException;
while (inner != null)
{
content.Append("The inner exception was ");
content.Append(inner.GetType().FullName);
content.Append("\n");
content.Append(inner.Message);
content.Append("\n");
inner = inner.InnerException;
}
}
context.Response.ContentType = "text/plain";
return context.Response.WriteAsync(content.ToString());
}
开发者ID:Bikeman868,项目名称:Urchin,代码行数:35,代码来源:FailedSetupMiddleware.cs
示例12: CheckToken
private async Task<bool> CheckToken(IOwinContext context)
{
if (!_options.RequireBearerToken)
{
return true;
}
if (!string.IsNullOrWhiteSpace(_options.BearerTokenValue))
{
const string bearerTypeToken = "Bearer";
var authorizationHeaders = context.Request.Headers.GetValues("Authorization");
if (authorizationHeaders != null && authorizationHeaders.Count > 0)
{
var header = authorizationHeaders[0].Trim();
if (header.StartsWith(bearerTypeToken))
{
var value = header.Substring(bearerTypeToken.Length).Trim();
if (!value.Equals(_options.BearerTokenValue))
{
context.Response.ContentType = "text/plain";
context.Response.StatusCode = (int)HttpStatusCode.Forbidden;
await context.Response.WriteAsync("Forbidden");
return false;
}
return true;
}
}
}
context.Response.ContentType = "text/plain";
context.Response.StatusCode = (int)HttpStatusCode.Unauthorized;
await context.Response.WriteAsync("Unauthorized");
return false;
}
开发者ID:NetChris,项目名称:NetChris.Web.SelfTest,代码行数:34,代码来源:SelfTestMiddleware.cs
示例13: SignInAsAlice
private Task SignInAsAlice(IOwinContext context)
{
context.Authentication.SignIn(
new AuthenticationProperties(),
new ClaimsIdentity(new GenericIdentity("Alice", "Cookies")));
return Task.FromResult<object>(null);
}
开发者ID:ricardodemauro,项目名称:katana-clone,代码行数:7,代码来源:CookieMiddlewareTests.cs
示例14: Invoke
public override Task Invoke(IOwinContext context)
{
var rep = context.Response;
rep.StatusCode = 404;
//判断调用次数,避免无限递归
var invokeTimes = context.Get<Int32>(INVOKE_TIMES);
invokeTimes++;
if (invokeTimes > 1 || String.IsNullOrEmpty(RewritePath))
{
String msg = "404 Not Found";
rep.ContentLength = msg.Length;
return rep.WriteAsync(msg);
}
context.Set(INVOKE_TIMES, invokeTimes);
context.Set<String>("owin.RequestPath", RewritePath);
OwinMiddleware first = server.GetFirstMiddlewareInstance();
if (first == null)
throw new ArgumentException($"Middleware '{this.GetType().FullName};{this.GetType().Assembly.GetName().Name}' must not be the first middleware,and recommand to be set to the last one.");
//清理OwinContext
foreach (var cleaner in server.GetMiddlewares<IOwinContextCleaner>())
cleaner.Clean(context);
return first.Invoke(context);
}
开发者ID:aaasoft,项目名称:Quick.OwinMVC,代码行数:27,代码来源:Error404Middleware.cs
示例15: OpenIdConnectValidateClientRedirectUriContext
internal OpenIdConnectValidateClientRedirectUriContext(
IOwinContext context,
OpenIdConnectServerOptions options,
OpenIdConnectMessage authorizationRequest)
: base(context, options, authorizationRequest)
{
}
开发者ID:cleancodenz,项目名称:WebAPI,代码行数:7,代码来源:OpenIdConnectValidateClientRedirectUriContext.cs
示例16: PrintCurrentIntegratedPipelineStage
private void PrintCurrentIntegratedPipelineStage(IOwinContext context, string msg)
{
var currentIntegratedpipelineStage = HttpContext.Current.CurrentNotification;
context.Get<TextWriter>("host.TraceOutput").WriteLine(
"Current IIS event: " + currentIntegratedpipelineStage
+ " Msg: " + msg);
}
开发者ID:TheFastCat,项目名称:OWINKatanaExamples,代码行数:7,代码来源:Startup.cs
示例17: Invoke
public override async Task Invoke(IOwinContext context)
{
Exception exception = null;
var stopWatch = Stopwatch.StartNew();
try
{
await Next.Invoke(context).ConfigureAwait(false);
}
catch (Exception e)
{
exception = e;
}
finally
{
stopWatch.Stop();
if (exception == null)
{
_logger.Verbose($"API {context.Request.Method} {stopWatch.Elapsed.TotalSeconds:0.00} sec {(HttpStatusCode)context.Response.StatusCode} {context.Request.Uri.GetLeftPart(UriPartial.Path)}");
}
else
{
_logger.Error(exception, $"API {context.Request.Method} {stopWatch.Elapsed.TotalSeconds:0.00} sec {(HttpStatusCode) context.Response.StatusCode} {context.Request.Uri.GetLeftPart(UriPartial.Path)}");
}
}
if (exception != null)
{
throw exception;
}
}
开发者ID:rasmus,项目名称:TheBorg,代码行数:32,代码来源:LoggerMiddleware.cs
示例18: WriteResponseAsync
public static async Task WriteResponseAsync(IOwinContext context, HttpStatusCode statusCode, Action<JsonWriter> writeContent)
{
/*
* If an exception is thrown when building the response body, the exception must be handled before returning
* a 200 OK (and presumably return a 500 Internal Server Error). If this approach becomes a memory problem,
* we can write directly to the response stream. However, we must be sure to a) have proper validation to
* avoid service exceptions (which is never a sure thing) or b) be okay with returning 200 OK on service
* exceptions. Another approach could also separate "do business logic" with "build response body". Since
* most exceptions will likely happen during the "do business logic" step, this would reduce the change of
* a 200 OK on service exception. However, this means that the whole result of the business logic is in
* memory.
*/
var content = new MemoryStream();
WriteToStream(content, writeContent);
content.Position = 0;
// write the response
context.Response.StatusCode = (int)statusCode;
context.Response.Headers.Add("Pragma", new[] { "no-cache" });
context.Response.Headers.Add("Cache-Control", new[] { "no-cache" });
context.Response.Headers.Add("Expires", new[] { "0" });
var callback = context.Request.Query["callback"];
if (string.IsNullOrEmpty(callback))
{
context.Response.ContentType = "application/json";
await content.CopyToAsync(context.Response.Body);
}
else
{
context.Response.ContentType = "application/javascript";
await context.Response.WriteAsync($"{callback}(");
await content.CopyToAsync(context.Response.Body);
await context.Response.WriteAsync(")");
}
}
开发者ID:NuGet,项目名称:Entropy,代码行数:35,代码来源:ResponseHelpers.cs
示例19: Invoke
public async override Task Invoke(IOwinContext context)
{
var _requset = context.Request;
var _gzipStream = new MemoryStream();
Byte[] _unzip;
Byte[] _zip;
//如果再 Http Header 條件符合下列項目才進行解壓縮作業
if (_requset.Headers["Content-Type"] == "application/gzip")
{
await _requset.Body.CopyToAsync(_gzipStream);
_gzipStream.Position = 0;
//如果包含壓縮內容,進行解壓縮
_zip = _gzipStream.ToArray();
_unzip = this.GZipUncompress(_zip);
//將解壓縮的 Byte 陣列匯入到 HttpRequest 內文
_requset.Body = new MemoryStream(_unzip);
_requset.Body.Position = 0;
//修改 Content-Type 為 application/json
_requset.Headers.Remove("Content-Type");
_requset.Headers.Add("Content-Type", new String[] { @"application/json" });
}
await Next.Invoke(context);
}
开发者ID:txstudio,项目名称:txstudio.Owin.GZipMiddleware,代码行数:29,代码来源:GZipMiddleware.cs
示例20: RankingsAsync
public static async Task RankingsAsync(IOwinContext context, NuGetSearcherManager searcherManager, ResponseWriter responseWriter)
{
await responseWriter.WriteResponseAsync(
context,
HttpStatusCode.OK,
jsonWriter => ServiceInfoImpl.Rankings(jsonWriter, searcherManager));
}
开发者ID:NuGet,项目名称:NuGet.Services.Metadata,代码行数:7,代码来源:ServiceEndpoints.cs
注:本文中的IOwinContext类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论