当前位置: 首页>>代码示例>>C#>>正文


C# Nancy类代码示例

本文整理汇总了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);
 }
开发者ID:rharrisxtheta,项目名称:BrightstarDB,代码行数:7,代码来源:FakeNancyBootstrapper.cs

示例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);
        }
开发者ID:mattanja,项目名称:kernetics.messenger,代码行数:31,代码来源:Bootstrapper.cs

示例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("{}");
        }
开发者ID:yodiwo,项目名称:plegma,代码行数:34,代码来源:Bootstrapper.cs

示例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));
        }
开发者ID:RayKwon,项目名称:comcamp_demo,代码行数:7,代码来源:Bootstrapper.cs

示例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);
        }
开发者ID:alexliu1987,项目名称:One.Authorization,代码行数:36,代码来源:Bootstrapper.cs

示例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);
        }
开发者ID:SvenLauterbach,项目名称:net-figo,代码行数:10,代码来源:Bootstrapper.cs

示例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"));
        }
开发者ID:kraki5525,项目名称:Testr,代码行数:7,代码来源:TestrBootstrapper.cs

示例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;
            });
        }
开发者ID:jacobhama,项目名称:asimov-deploy-winagent,代码行数:26,代码来源:CustomNancyBootstrapper.cs

示例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;
        }
开发者ID:prabirshrestha,项目名称:NancyFacebookSample,代码行数:32,代码来源:Facebook.Bootstrapper.cs

示例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);
        }
开发者ID:patrickmaliwatiq,项目名称:planogram,代码行数:7,代码来源:Bootstrapper.cs

示例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));
        }
开发者ID:davidwhitney,项目名称:deployd-micro,代码行数:7,代码来源:NancyConventionsBootstrapper.cs

示例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;
                });
        }
开发者ID:prabirshrestha,项目名称:NancyFacebookSample,代码行数:30,代码来源:Bootstrapper.cs

示例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);
     });
 }
开发者ID:TheDarkVoid,项目名称:Karuta,代码行数:7,代码来源:NancyCustomConventionsBootstrap.cs

示例14: ApplicationStartup

 protected override void ApplicationStartup(Nancy.TinyIoc.TinyIoCContainer container, Nancy.Bootstrapper.IPipelines pipelines)
 {
     if (_authenticationProvider != null)
     {
         _authenticationProvider.Enable(pipelines);
     }
 }
开发者ID:GTuritto,项目名称:BrightstarDB,代码行数:7,代码来源:FakeNancyBootstrapper.cs

示例15: ConfigureApplicationContainer

        protected override void ConfigureApplicationContainer(Nancy.TinyIoc.TinyIoCContainer container)
        {
            base.ConfigureApplicationContainer(container);

            container.Register<IPackageService>(_testFixture.PackageService);
            container.Register<IGlobalSettingsService>(_testFixture.GlobalSettingsService);
        }
开发者ID:dealproc,项目名称:Drey,代码行数:7,代码来源:OwinPipeline.cs


注:本文中的Nancy类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。