本文整理汇总了C#中Nancy类的典型用法代码示例。如果您正苦于以下问题:C# Nancy类的具体用法?C# Nancy怎么用?C# Nancy使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Nancy类属于命名空间,在下文中一共展示了Nancy类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ConfigureApplicationContainer
protected override void ConfigureApplicationContainer(Nancy.TinyIoc.TinyIoCContainer container)
{
base.ConfigureApplicationContainer(container);
container.Register<IBrightstarService>(_brightstarService);
container.Register<AbstractStorePermissionsProvider>(_storePermissionsProvider);
container.Register(_systemPermissionsProvider);
}
示例2: ApplicationStartup
protected override void ApplicationStartup(Nancy.TinyIoc.TinyIoCContainer container, Nancy.Bootstrapper.IPipelines pipelines) {
// Setup IoC
container.Register<IDataStore>(new kernetics.messenger.database.DataStore());
//container.Register<IUserMapper>();
// TODO: Setup authentication
//var formsAuthConfiguration = new Nancy.Authentication.Forms.FormsAuthenticationConfiguration() {
// RedirectUrl = "~/login",
// UserMapper = container.Resolve<IUserMapper>(),
//};
//Nancy.Authentication.Forms.FormsAuthentication.Enable(pipelines, formsAuthConfiguration);
// Error handling
pipelines.OnError += (context, exception) => {
if (exception is Exception) {
return new Response() {
StatusCode = HttpStatusCode.NotFound,
ContentType = "text/html",
Contents = (stream) => {
var errorMessage = Encoding.UTF8.GetBytes(exception.Message);
stream.Write(errorMessage, 0, errorMessage.Length);
}
};
}
Console.WriteLine("Error");
return null;
};
base.ApplicationStartup(container, pipelines);
}
示例3: ApplicationStartup
protected override void ApplicationStartup(Nancy.TinyIoc.TinyIoCContainer container, Nancy.Bootstrapper.IPipelines pipelines)
{
base.ApplicationStartup(container, pipelines);
//Enable CSRF protection
Nancy.Security.Csrf.Enable(pipelines);
// Enabled cookie sessions
Nancy.Session.CookieBasedSessions.Enable(pipelines);
//Setup frame and origin options ( https://www.owasp.org/index.php/List_of_useful_HTTP_headers )
//may be overwritten by server (apache,ngix,iis,..) for config see https://developer.mozilla.org/en-US/docs/Web/HTTP/X-Frame-Options
pipelines.AfterRequest.AddItemToEndOfPipeline((ctx) =>
{
if (ctx.Response.StatusCode == HttpStatusCode.InternalServerError) return;
ctx.Response.Headers.Add("X-Frame-Options", "SAMEORIGIN");
ctx.Response.Headers.Add("X-Download-Options", "noopen"); // IE extension
ctx.Response.Headers.Add("X-Content-Type-Options", "nosniff");
ctx.Response.Headers.Add("X-XSS-Protection", "1; mode=block");
});
// Retain the casing in serialization of nancy json
Nancy.Json.JsonSettings.RetainCasing = true;
StaticConfiguration.CaseSensitive = false;
// Enable debugging of nancy
StaticConfiguration.EnableRequestTracing = false;
// Dummy call to force the include of the Nancy.Serialization.JsonNet dll
JsonNetSerializer a = new JsonNetSerializer();
a.CanSerialize("{}");
}
示例4: ConfigureApplicationContainer
protected override void ConfigureApplicationContainer(Nancy.TinyIoc.TinyIoCContainer container)
{
base.ConfigureApplicationContainer(container);
// register custom json serializer, camelCase in this case
container.Register(typeof(JsonSerializer), typeof(CustomJsonSerializer));
}
示例5: 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(Nancy.TinyIoc.TinyIoCContainer container, Nancy.Bootstrapper.IPipelines pipelines)
{
// pipelines.RegisterCompressionCheck();
pipelines.AfterRequest += (ctx) =>
{
// if (ctx.Response.ContentType == "text/html")
// ctx.Response.ContentType = ctx.Response.ContentType + "; charset=utf-8";
// var response = ctx.Response;
// var contents = response.Contents;
// response.Contents = responseStream =>
// {
// using (var stream = new StreamWriter(responseStream, Encoding.UTF8))
// {
// contents(stream.BaseStream);
// }
// // var stream = new StreamReader(responseStream, Encoding.UTF8);
// };
// var jsonBytes = Encoding.UTF8.GetBytes();
// return new Response
// {
// ContentType = "application/json",
// Contents = s => s.Write(jsonBytes, 0, jsonBytes.Length)
// };
};
//显示详细错误
StaticConfiguration.DisableErrorTraces = false;
//设置Json字符串最大长度
Nancy.Json.JsonSettings.MaxJsonLength = int.MaxValue;
base.ApplicationStartup(container, pipelines);
}
示例6: 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(Nancy.TinyIoc.TinyIoCContainer container, Nancy.Bootstrapper.IPipelines pipelines)
{
base.ApplicationStartup(container, pipelines);
StaticConfiguration.DisableErrorTraces = false;
CookieBasedSessions.Enable(pipelines);
}
示例7: ConfigureConventions
protected override void ConfigureConventions(Nancy.Conventions.NancyConventions nancyConventions)
{
base.ConfigureConventions(nancyConventions);
nancyConventions.StaticContentsConventions.Add(StaticContentConventionBuilder.AddDirectory("Content"));
nancyConventions.StaticContentsConventions.Add(StaticContentConventionBuilder.AddDirectory("Scripts"));
}
示例8: ApplicationStartup
protected override void ApplicationStartup(IContainer container, Nancy.Bootstrapper.IPipelines pipelines)
{
base.ApplicationStartup(container, pipelines);
var config = container.GetInstance<IAsimovConfig>();
var tempReportsFolder = Path.Combine(config.TempFolder, "AsimovTempReports");
GenericFileResponse.SafePaths.Add(tempReportsFolder);
Conventions.StaticContentsConventions.Add(
StaticContentConventionBuilder.AddDirectory("temp-reports", tempReportsFolder)
);
pipelines.BeforeRequest.AddItemToEndOfPipeline(ctx =>
{
if (ctx.Request.Method == "POST")
{
if (ctx.Request.Headers.Authorization != config.ApiKey)
{
return 401;
}
}
return null;
});
}
示例9: FacebookRequestStartup
private Response FacebookRequestStartup(TinyIoC.TinyIoCContainer container, Nancy.Bootstrapper.IPipelines pipelines, NancyContext context)
{
if (context.Request != null)
{
string[] perms = null;
dynamic signedRequest;
var fbApp = container.Resolve<IFacebookApplication>();
if (context.TryParseFacebookSignedRequest(fbApp.AppId, fbApp.AppSecret, out signedRequest))
{
if (((System.Collections.Generic.IDictionary<string, object>)signedRequest).ContainsKey("oauth_token"))
{
var fb = container.Resolve<FacebookClient>();
fb.AccessToken = signedRequest.oauth_token;
try
{
var result = (IDictionary<string, object>)fb.Get("me/permissions");
perms = ((IDictionary<string, object>)((IList<object>)result["data"])[0]).Keys.ToArray();
}
catch (FacebookOAuthException)
{
// access token is invalid so perms=none
// but don't throw exception.
fb.AccessToken = null;
}
}
}
context.Items[CustomFacebookExtensions.FacebookPermsKey] = perms ?? new string[0];
}
return null;
}
示例10: ApplicationStartup
protected override void ApplicationStartup(IWindsorContainer container, Nancy.Bootstrapper.IPipelines pipelines)
{
//TODO: Uncomment once deployment dashboard work resumes
// new DataUpgrade().ExecuteDataUpgrade();
base.ApplicationStartup(container, pipelines);
}
示例11: ApplicationStartup
protected override void ApplicationStartup(Ninject.IKernel container, Nancy.Bootstrapper.IPipelines pipelines)
{
base.ApplicationStartup(container, pipelines);
Conventions.ViewLocationConventions.Add((viewName, model, context) => string.Concat("../../Views/", context.ModuleName.Replace("Controller", ""), "/", viewName));
Conventions.ViewLocationConventions.Add((viewName, model, context) => string.Concat("Views/", context.ModuleName.Replace("Controller", ""), "/", viewName));
}
示例12: RequestStartup
protected override void RequestStartup(TinyIoC.TinyIoCContainer container, Nancy.Bootstrapper.IPipelines pipelines, NancyContext context)
{
base.RequestStartup(container, pipelines, context);
pipelines.BeforeRequest.AddItemToStartOfPipeline(
ctx =>
{
var facebookClient = container.Resolve<Facebook.FacebookClient>();
var fbUser = context.CurrentUser as IFacebookUser;
if (fbUser != null)
facebookClient.AccessToken = fbUser.FacebookAccessToken;
#region SignedRequest
if (context.Request != null)
{
dynamic signedRequest;
var fbApp = container.Resolve<Facebook.IFacebookApplication>();
if (context.Request.TryParseFacebookSignedRequest(fbApp.AppId, fbApp.AppSecret, out signedRequest))
{
if (signedRequest.ContainsKey("oauth_token"))
facebookClient.AccessToken = signedRequest.oauth_token;
}
}
#endregion
return null;
});
}
示例13: ApplicationStartup
protected override void ApplicationStartup(TinyIoCContainer container, Nancy.Bootstrapper.IPipelines pipelines)
{
Conventions.ViewLocationConventions.Add((viewName, model, context) =>
{
return string.Concat(RinDB.VIEW_LOCATION, viewName);
});
}
示例14: ApplicationStartup
protected override void ApplicationStartup(Nancy.TinyIoc.TinyIoCContainer container, Nancy.Bootstrapper.IPipelines pipelines)
{
if (_authenticationProvider != null)
{
_authenticationProvider.Enable(pipelines);
}
}
示例15: ConfigureApplicationContainer
protected override void ConfigureApplicationContainer(Nancy.TinyIoc.TinyIoCContainer container)
{
base.ConfigureApplicationContainer(container);
container.Register<IPackageService>(_testFixture.PackageService);
container.Register<IGlobalSettingsService>(_testFixture.GlobalSettingsService);
}