本文整理汇总了C#中IOwinContext.Get方法的典型用法代码示例。如果您正苦于以下问题:C# IOwinContext.Get方法的具体用法?C# IOwinContext.Get怎么用?C# IOwinContext.Get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IOwinContext
的用法示例。
在下文中一共展示了IOwinContext.Get方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Invoke
public override async Task Invoke(IOwinContext context)
{
// Determine correlation id.
var correlationId = context.Get<string>(OwinRequestIdKey);
// The NuGet Gallery sends us the X-CorrelationId header.
// If that header is present, override OWIN's owin.RequestId.
string[] temp = null;
if (context.Request.Headers.TryGetValue(CorrelationIdHeaderKey, out temp))
{
correlationId = temp[0];
context.Set(OwinRequestIdKey, correlationId);
}
// As a bonus, make Serilog aware of this request ID as well.
if (HttpContext.Current != null)
{
HttpContext.Current.Items[SerilogRequestIdItemName] = Guid.Parse(correlationId);
}
// Run all the things
await Next.Invoke(context);
// Set response header
context.Response.Headers.Add("X-CorrelationId", new[] { context.Get<string>(OwinRequestIdKey) });
}
示例2: Invoke
public override Task Invoke(IOwinContext context)
{
if (context.Get<string>("p1") == "p1" && context.Get<int>("p2") == 2 && context.Get<object>("p3").ToString() == "p3")
{
return context.Response.WriteAsync("SUCCESS");
}
else
{
return context.Response.WriteAsync("FAILURE");
}
}
示例3: 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);
}
示例4: 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);
}
示例5: Invoke
/// <summary>
/// Main entry point of middleware.
/// </summary>
/// <param name="context">Owin Context</param>
/// <returns>Task</returns>
public async override Task Invoke(IOwinContext context)
{
await Next.Invoke(context);
var setCookie = context.Response.Headers.GetValues("Set-Cookie");
if (setCookie != null)
{
var cookies = CookieParser.Parse(setCookie);
foreach (var c in cookies)
{
// Guard for stability, preventing nullref exception
// in case private reflection breaks.
if (fromHeaderProperty != null)
{
// Mark the cookie as coming from a header, to prevent
// System.Web from adding it again.
fromHeaderProperty.SetValue(c, true);
}
// HttpContext.Current turns to null in some cases after the
// async call to Next.Invoke() when run in a web forms
// application. Let's grab it from the owin environment
// instead.
var httpContext = context.Get<HttpContextBase>(typeof(HttpContextBase).FullName);
if (httpContext != null &&
!httpContext.Response.Cookies.AllKeys.Contains(c.Name))
{
httpContext.Response.Cookies.Add(c);
}
}
}
}
示例6: CreateManager
private static UserManager<IdentityUser> CreateManager(IdentityFactoryOptions<UserManager<IdentityUser>> options, IOwinContext context)
{
var userStore = new UserStore<IdentityUser>(context.Get<OAuthDbContext>());
var manager = new UserManager<IdentityUser>(userStore);
return manager;
}
示例7: AuthenticationRepository
public AuthenticationRepository(IOwinContext owinContext)
{
userManager = owinContext.GetUserManager<ApplicationUserManager>();
roleManager = owinContext.Get<ApplicationRoleManager>();
authenticationManager = owinContext.Authentication;
request = owinContext.Request;
}
示例8: 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);
}
}
}
示例9: Invoke
public override Task Invoke(IOwinContext context)
{
validateStage(context, expectedStageName, middlewareId);
context.Get<Stack<int>>("stack").Push(middlewareId);
return this.Next.Invoke(context).ContinueWith((result) =>
{
validateStage(context, RequestNotification.EndRequest, middlewareId);
var expectedMiddlewareId = context.Get<Stack<int>>("stack").Pop();
if (expectedMiddlewareId != middlewareId)
{
throw new Exception(string.Format(Error_Incorrect_Middleware_Unwinding, expectedMiddlewareId, middlewareId));
}
});
}
示例10: Create
public static CategoryManager Create(IdentityFactoryOptions<CategoryManager> options, IOwinContext context)
{
ICategoryDataAccess categoryData = context.Get<SqlConnection>().As<ICategoryDataAccess>();
CategoryManager manager = new CategoryManager(categoryData);
return manager;
}
示例11: Service
public string Service(IOwinContext context, IDictionary<string, object> data)
{
var rep = context.Response;
context.GetSession().Clear();
rep.Redirect(context.Get<String>("ContextPath"));
return null;
}
示例12: PaymentService
public PaymentService(IUserService userService, IEmailService emailService)
{
_emailService = emailService;
_userService = userService;
_owin = HttpContext.Current.GetOwinContext();
_dbContext = _owin.Get<ApplicationDbContext>();
}
示例13: Create
// callback function for IAppBuilder.CreatePerOwinContext
public static AccountManager Create(IdentityFactoryOptions<AccountManager> options, IOwinContext context)
{
IAccountDataAccess accountData = context.Get<SqlConnection>().As<IAccountDataAccess>();
AccountManager manager = new AccountManager(accountData);
return manager;
}
示例14: Invoke
public Task Invoke(IOwinContext context, Func<Task> next)
{
var request = context.Request;
if (request.Method != "GET" || !_path.IsWildcardMatch(request.Path))
return next.Invoke();
var environment = request.Query["environment"];
var machine = request.Query["machine"];
var application = request.Query["application"];
var instance = request.Query["instance"];
if (string.IsNullOrWhiteSpace(machine))
throw new HttpException((int)HttpStatusCode.BadRequest, "Machine parameter is required");
if (string.IsNullOrWhiteSpace(application))
throw new HttpException((int)HttpStatusCode.BadRequest, "Application parameter is required");
try
{
var clientCredentials = context.Get<IClientCredentials>("ClientCredentials");
var config = _ruleData.TraceConfig(clientCredentials, environment, machine, application, instance);
context.Response.ContentType = "application/json";
return context.Response.WriteAsync(config.ToString(Formatting.Indented));
}
catch (Exception ex)
{
if (ex is HttpException) throw;
throw new HttpException((int)HttpStatusCode.InternalServerError, ex.Message, ex);
}
}
示例15: Invoke
public override Task Invoke(IOwinContext context)
{
String path = context.Get<String>("owin.RequestPath");
if (rewriteDict.ContainsKey(path))
context.Set<String>("owin.RequestPath", rewriteDict[path]);
return Next.Invoke(context);
}