本文整理汇总了C#中Nancy.NancyContext.GetOwinEnvironment方法的典型用法代码示例。如果您正苦于以下问题:C# NancyContext.GetOwinEnvironment方法的具体用法?C# NancyContext.GetOwinEnvironment怎么用?C# NancyContext.GetOwinEnvironment使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Nancy.NancyContext
的用法示例。
在下文中一共展示了NancyContext.GetOwinEnvironment方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: RequestStartup
protected override void RequestStartup(TinyIoCContainer container, IPipelines pipelines, NancyContext context)
{
base.RequestStartup(container, pipelines, context);
var owinEnvironment = context.GetOwinEnvironment();
var user = owinEnvironment["server.User"] as ClaimsPrincipal;
context.CurrentUser = new DemoUserIdentity()
{
UserName = user.Identity.Name,
Claims = user.Claims.Select(x => x.Value)
};
}
示例2: RequestStartup
protected override void RequestStartup(IContainer container, IPipelines pipelines, NancyContext context)
{
base.RequestStartup(container, pipelines, context);
var owinEnvironment = context.GetOwinEnvironment();
if (!owinEnvironment.ContainsKey("server.User")) return;
var user = owinEnvironment["server.User"] as ClaimsPrincipal;
if (user != null && user.Identity.IsAuthenticated)
{
context.CurrentUser =
new CustomUserIdentity(Guid.Parse(user.Claims.Single(x => x.Type == ClaimTypes.NameIdentifier).Value),
user.Identity.Name, user.Claims.Select(x => x.Value));
}
}
示例3: RequestStartup
protected override void RequestStartup(TinyIoCContainer container, IPipelines pipelines, NancyContext context)
{
base.RequestStartup(container, pipelines, context);
var owinEnvironment = context.GetOwinEnvironment();
var user = owinEnvironment["server.User"] as ClaimsPrincipal;
if (user != null)
{
context.CurrentUser = new DemoUserIdentity()
{
UserName = user.Identity.Name,
Claims = user.Claims.Where(x => x.Type == "http://schemas.microsoft.com/ws/2008/06/identity/claims/role").Select(x => x.Value)
};
}
}
示例4: RequestStartup
protected override void RequestStartup(TinyIoCContainer container, IPipelines pipelines, NancyContext context)
{
base.RequestStartup(container, pipelines, context);
StaticConfiguration.DisableErrorTraces = false;
var owinEnvironment = context.GetOwinEnvironment();
var user = owinEnvironment["server.User"] as ClaimsPrincipal;
if (user != null)
{
context.CurrentUser = new DemoUserIdentity
{
UserName = user.Identity.Name,
Claims = user.Claims.Where(x => x.Type == "http://schemas.microsoft.com/ws/2008/06/identity/claims/role").Select(x => x.Value)
};
}
pipelines.OnError.AddItemToEndOfPipeline((z, a) =>
{
return null;
});
}
示例5: FlowPrincipal
private static Response FlowPrincipal(NancyContext context)
{
var env = context.GetOwinEnvironment();
if (env == null)
return null;
var principal = env.Get<IPrincipal>("server.User") as ClaimsPrincipal;
if (principal != null)
context.CurrentUser = new TheBenchUser(new TheBenchPrincipal(principal));
return null;
}