本文整理汇总了C#中IPipelines类的典型用法代码示例。如果您正苦于以下问题:C# IPipelines类的具体用法?C# IPipelines怎么用?C# IPipelines使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
IPipelines类属于命名空间,在下文中一共展示了IPipelines类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: RequestStartup
protected override void RequestStartup(TinyIoCContainer container, IPipelines pipelines, NancyContext context)
{
var formsAuthConfiguration =
new FormsAuthenticationConfiguration()
{
RedirectUrl = "~/login",
UserMapper = container.Resolve<IUserMapper>(),
};
FormsAuthentication.Enable(pipelines, formsAuthConfiguration);
CookieBasedSessions.Enable(pipelines);
pipelines.BeforeRequest.AddItemToStartOfPipeline(ctx =>
{
if (Helper.Settings.Instance.Client.CanConnect)
return null;
else
{
if (String.Compare(ctx.Request.Path, "/notavailable", true) == 0)
{
return null;
}
return new RedirectResponse("/notavailable");
}
});
base.RequestStartup(container, pipelines, context);
}
示例2: Initialize
public void Initialize(IPipelines pipelines)
{
pipelines.BeforeRequest.AddItemToStartOfPipeline(RunCassetteHandler);
pipelines.BeforeRequest.AddItemToStartOfPipeline(InitializeCassetteRequestState);
pipelines.AfterRequest.AddItemToEndOfPipeline(RewriteResponseContents);
}
示例3: ApplicationStartup
protected override void ApplicationStartup(TinyIoCContainer container, IPipelines pipelines)
{
base.ApplicationStartup(container, pipelines);
// In reality you would use a pre-built authentication/claims provider
pipelines.BeforeRequest += (ctx) =>
{
// World's-worse-authentication (TM)
// Pull the username out of the querystring if it exists
// and build claims from it
var username = ctx.Request.Query.username;
if (username.HasValue)
{
ctx.CurrentUser = new DemoUserIdentity
{
UserName = username.ToString(),
Claims = BuildClaims(username.ToString())
};
}
return null;
};
pipelines.AfterRequest += (ctx) =>
{
// If status code comes back as Unauthorized then
// forward the user to the login page
if (ctx.Response.StatusCode == HttpStatusCode.Unauthorized)
{
ctx.Response = new RedirectResponse("/login?returnUrl=" + Uri.EscapeDataString(ctx.Request.Path));
}
};
}
示例4: RequestStartup
protected override void RequestStartup(TinyIoCContainer container, IPipelines pipelines, NancyContext context)
{
var formsAuthConfig = new FormsAuthenticationConfiguration
{
RedirectUrl = "~/login",
UserMapper = container.Resolve<IUserMapper>()
};
FormsAuthentication.Enable(pipelines, formsAuthConfig);
pipelines.AfterRequest += ctx =>
{
var dbContext = container.Resolve<SmartFlowContext>();
dbContext.SaveChanges();
};
pipelines.OnError += (ctx, ex) =>
{
var logger = container.Resolve<TextFileLogger>();
logger.Write("Error", Enums.LogLevel.ApplicationError, ex);
return ErrorResponse.FromException(ex);
};
base.RequestStartup(container, pipelines, context);
}
示例5: Initialize
/// <summary>
/// Perform any initialisation tasks
/// </summary>
/// <param name="pipelines">Application pipelines</param>
/// <param name="context">The current context</param>
public void Initialize(IPipelines pipelines, NancyContext context)
{
// On each request, store the NancyContext in the LogicalCallContext
CallContext.LogicalSetData(NancyConfiguration.NancyContextDataSlot, context);
var nancyConfiguration = NancyConfiguration.Settings;
if (nancyConfiguration == null)
return;
var name = nancyConfiguration.PipelineName.Value;
var sharpRaven = new PipelineItem(name, (nancyContext, exception) =>
{
if (nancyConfiguration.CaptureExceptionOnError.Value)
{
var guid = this.ravenClient.CaptureException(exception);
if (guid != null)
{
context.Items.Add(NancyConfiguration.SentryEventGuidKey, guid);
exception.Data.Add(NancyConfiguration.SentryEventGuidKey, guid);
}
}
return null;
});
pipelines.OnError.AddItemToStartOfPipeline(sharpRaven);
}
示例6: ApplicationStartup
protected override void ApplicationStartup(TinyIoCContainer container, IPipelines pipelines)
{
base.ApplicationStartup(container, pipelines);
var configuration = new BasicAuthenticationConfiguration(container.Resolve<IUserValidator>(), "test-realm");
BasicAuthentication.Enable(pipelines,configuration);
var stateless = new StatelessAuthenticationConfiguration(c =>
{
const string key = "X-Auth-Token";
string token = null;
if (c.Request.Headers.Authorization == null || !c.Request.Headers.Authorization.Any())
{
_log.ErrorFormat("No request headers are present in the request {0}", c);
return null;
}
if (c.Request.Headers.FirstOrDefault(f => f.Key == key).Value == null ||
string.IsNullOrEmpty(c.Request.Headers.FirstOrDefault(f => f.Key == key).Value.First()))
{
_log.ErrorFormat("No Key present in the request headers");
return null;
}
token = c.Request.Headers.FirstOrDefault(f => f.Key == key).Value.First();
_log.InfoFormat("Token used {0}", token);
var user = container.Resolve<IUserApiMapper>();
return user.GetUserFromToken(token);
});
StatelessAuthentication.Enable(pipelines, stateless);
}
示例7: ApplicationStartup
protected override void ApplicationStartup(TinyIoC.TinyIoCContainer container, IPipelines pipelines)
{
FormsAuthentication.Enable(pipelines, new FormsAuthenticationConfiguration {
RedirectUrl = "~/login",
UserMapper = _mocks[typeof(IUserRepository)] as IUserRepository
});
}
示例8: ApplicationStartup
protected override void ApplicationStartup(ILifetimeScope container, IPipelines pipelines)
{
StaticConfiguration.DisableErrorTraces = false;
// Enable memory sessions, and secure them against session hijacking
pipelines.EnableInProcSessions();
pipelines.BeforeRequest.AddItemToStartOfPipeline(ctx => {
var antiSessionHijackLogic = container.Resolve<IAntiSessionHijackLogic>();
return antiSessionHijackLogic.InterceptHijackedSession(ctx.Request);
});
pipelines.AfterRequest.AddItemToEndOfPipeline(ctx => {
var antiSessionHijackLogic = container.Resolve<IAntiSessionHijackLogic>();
antiSessionHijackLogic.ProtectResponseFromSessionHijacking(ctx);
});
// Load the user from the AspNet session. If one is found, create a Nancy identity and assign it.
pipelines.BeforeRequest.AddItemToEndOfPipeline(ctx => {
var identityAssigner = container.Resolve<INancyIdentityFromContextAssigner>();
identityAssigner.AssignNancyIdentityFromContext(ctx);
return null;
});
pipelines.OnError = pipelines.OnError
+ ErrorPipelines.HandleModelBindingException()
+ ErrorPipelines.HandleRequestValidationException()
+ ErrorPipelines.HandleSecurityException();
base.ApplicationStartup(container, pipelines);
}
示例9: Enable
/// <summary>
/// Enables forms authentication for the application
/// </summary>
/// <param name="pipelines">Pipelines to add handlers to (usually "this")</param>
/// <param name="configuration">Forms authentication configuration</param>
public static void Enable(IPipelines pipelines, FormsAuthenticationConfiguration configuration)
{
if (pipelines == null)
{
throw new ArgumentNullException("pipelines");
}
if (configuration == null)
{
throw new ArgumentNullException("configuration");
}
if (!configuration.IsValid)
{
throw new ArgumentException("Configuration is invalid", "configuration");
}
currentConfiguration = configuration;
pipelines.BeforeRequest.AddItemToStartOfPipeline(GetLoadAuthenticationHook(configuration));
if (!configuration.DisableRedirect)
{
pipelines.AfterRequest.AddItemToEndOfPipeline(GetRedirectToLoginHook(configuration));
}
}
示例10: ApplicationStartup
// The bootstrapper enables you to reconfigure the composition of the framework,
// by overriding the various methods and properties.
// For more information https://github.com/NancyFx/Nancy/wiki/Bootstrapper
protected override void ApplicationStartup(TinyIoCContainer container, IPipelines pipelines)
{
container.Register<IStorage, Storage>().AsSingleton();
container.Register<CredentialsStorage>().AsSingleton();
var serverScheduler = new ServerScheduler(container.Resolve<IStorage>());
serverScheduler.Start();
}
示例11: ApplicationStartup
/// <summary>
/// Applications the startup.
/// </summary>
/// <param name="container">The container.</param>
/// <param name="pipelines">The pipelines.</param>
protected override void ApplicationStartup(TinyIoCContainer container, IPipelines pipelines)
{
base.ApplicationStartup(container, pipelines);
pipelines.BeforeRequest += ctx =>
{
var identity = (WindowsIdentity)HttpContext.Current.User.Identity;
if (identity.IsAuthenticated)
{
// Resolve<UserManager>
// Get from DB/Cache
// Add user to ICurrentUSerProvider
// Get Claims
ctx.CurrentUser = new DemoUserIdentity
{
UserName = identity.Name,
Claims = new[] { "Basic", "Finance" }
};
}
return null;
};
pipelines.AfterRequest += ctx =>
{
// If status code comes back as Unauthorized then
// forward the user to the unauthorised page
//if (ctx.Response.StatusCode == HttpStatusCode.Unauthorized
// || ctx.Response.StatusCode == HttpStatusCode.Forbidden)
//{
// ctx.Response = new RedirectResponse("/Unauthorised");
//}
};
}
示例12: RequestStartup
protected override void RequestStartup(IWindsorContainer container, IPipelines pipelines, NancyContext context)
{
//var formsAuthConfiguration = new FormsAuthenticationConfiguration
//{
// RedirectUrl = "/login",
// UserMapper = container.Resolve<IUserMapper>(),
//};
//FormsAuthentication.Enable(pipelines, formsAuthConfiguration);
pipelines.BeforeRequest.AddItemToEndOfPipeline(ctx =>
{
if (ctx.CurrentUser != null) ctx.ViewBag.UserName = ctx.CurrentUser.UserName;
return null;
});
pipelines.BeforeRequest.AddItemToStartOfPipeline(nancyContext =>
{
//nancyContext.Request.Headers.UserAgent = "Lightstone";
var token = "";
var cookie = nancyContext.Request.Headers.Cookie.FirstOrDefault(x => (x.Name + "").ToLower() == "token");
if (cookie != null)
token = HttpUtility.UrlDecode(cookie.Value);
//nancyContext.Request.Headers.Authorization = "Token {0}".FormatWith(HttpUtility.UrlDecode(token.Value));
var user = container.Resolve<ITokenizer>().Detokenize(token, nancyContext, new DefaultUserIdentityResolver());
if (user != null)
nancyContext.CurrentUser = user;
return null;
});
TokenAuthentication.Enable(pipelines, new TokenAuthenticationConfiguration(container.Resolve<ITokenizer>()));
}
示例13: ApplicationStartup
protected override void ApplicationStartup(TinyIoCContainer container, IPipelines pipelines)
{
base.ApplicationStartup(container, pipelines);
// Add an error handler to catch our entity not found exceptions
pipelines.OnError += (context, exception) =>
{
// If we've raised an EntityNotFound exception in our data layer
if (exception is EntityNotFoundException)
return new Response()
{
StatusCode = HttpStatusCode.NotFound,
ContentType = "text/html",
Contents = (stream) =>
{
var errorMessage = Encoding.UTF8.GetBytes("A Data Entity with the requested ID was not found in the database.");
stream.Write(errorMessage, 0, errorMessage.Length);
}
};
// If none of the above handles our exception, then pass it on as a 500
throw exception;
};
// End error handler
CookieBasedSessions.Enable(pipelines);
}
示例14: RequestStartup
protected override void RequestStartup(ILifetimeScope container, IPipelines pipelines, NancyContext context)
{
// No registrations should be performed in here, however you may
// resolve things that are needed during request startup.
FormsAuthentication.Enable(pipelines, new FormsAuthenticationConfiguration()
{
RedirectUrl = "~/account/login",
UserMapper = container.Resolve<IUserMapper>(),
});
pipelines.BeforeRequest.AddItemToEndOfPipeline(c =>
{
if (c.CurrentUser.IsAuthenticated())
{
container.Resolve<ITenantContext>().SetTenantId(c.CurrentUser.AsAuthenticatedUser().Id, c.CurrentUser.HasClaim("Admin"));
c.ViewBag.UserName = c.CurrentUser.AsAuthenticatedUser().FullName;
c.ViewBag.IsAdmin = c.CurrentUser.HasClaim("Admin");
}
else
container.Resolve<ITenantContext>().SetTenantId(null, false);
return null;
});
}
示例15: ApplicationStartup
protected override void ApplicationStartup(ILifetimeScope container, IPipelines pipelines)
{
base.ApplicationStartup(container, pipelines);
// register interfaces/implementations
container.Update(builder => builder
//.RegisterType<CouchDbTShirtRepository>()
.RegisterType<MockedTShirtRepository>()
.As<ITShirtRepository>());
// register MyCouchStore parameter for couchdb repo classes
container.Update(builder => builder
.RegisterType<MyCouchStore>()
.As<IMyCouchStore>()
.UsingConstructor(typeof (string), typeof (string))
.WithParameters(new [] {
new NamedParameter("dbUri","http://seraya_dba:[email protected]:5984/"),
new NamedParameter("dbName","cshirts")
})
);
// TODO: remove after implementing REST-Api & replacing razor with angular
// display razor error messages
StaticConfiguration.DisableErrorTraces = false;
}