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


C# IAppBuilder.Use方法代码示例

本文整理汇总了C#中IAppBuilder.Use方法的典型用法代码示例。如果您正苦于以下问题:C# IAppBuilder.Use方法的具体用法?C# IAppBuilder.Use怎么用?C# IAppBuilder.Use使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IAppBuilder的用法示例。


在下文中一共展示了IAppBuilder.Use方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Configuration

        public void Configuration(IAppBuilder app)
        {
            var settings = new ApplicationSettings();

            if (settings.MigrateDatabase)
            {
                // Perform the required migrations
                DoMigrations();
            }

            var kernel = SetupNinject(settings);

            app.Use(typeof(DetectSchemeHandler));

            if (settings.RequireHttps)
            {
                app.Use(typeof(RequireHttpsHandler));
            }

            app.UseShowExceptions();

            // This needs to run before everything
            app.Use(typeof(AuthorizationHandler), kernel.Get<IAuthenticationTokenService>());

            SetupSignalR(kernel, app);
            SetupWebApi(kernel, app);
            SetupMiddleware(settings, app);
            SetupNancy(kernel, app);

            SetupErrorHandling();
        }
开发者ID:bartsipes,项目名称:JabbR,代码行数:31,代码来源:Startup.cs

示例2: ConfigAuth

        public void ConfigAuth(IAppBuilder app)
        {
            app.SetDefaultSignInAsAuthenticationType(CookieAuthenticationDefaults.AuthenticationType);

            app.UseCookieAuthentication(new CookieAuthenticationOptions {});

            //[email protected]
            //Azure680628
            app.Use(async (context, next) =>
            {
                await next.Invoke();
            });

            app.UseOpenIdConnectAuthentication(
                new OpenIdConnectAuthenticationOptions
                {
                    // Client Id of Application
                    ClientId = "24e8d712-4765-48f1-9698-9e335da6f780",

                    // The authority provides a discoverable openid service
                    //https://login.windows.net/JohnsonAzureAD.onmicrosoft.com/.well-known/openid-configuration

                    // The keys
                    //https://login.windows.net/common/discovery/keys

                    Authority = "https://login.windows.net/JohnsonAzureAD.onmicrosoft.com",
                    PostLogoutRedirectUri = "http://localhost:53509/"
                });

            app.Use(async (context, next) =>
            {
               await next.Invoke();
            });
        }
开发者ID:cleancodenz,项目名称:WebAPI,代码行数:34,代码来源:Startup.Auth.cs

示例3: Configuration

        public void Configuration(IAppBuilder app)
        {
            if (Debugger.IsAttached)
            {
                app.Use(async (_http, _next) =>
                    {
                        await _next();

                        Console.WriteLine($"{_http.Response.StatusCode}: {_http.Request.Uri}");
                    });
            }

            app.Use((_http, _next) =>
                {
                    if (_http.Request.Headers.ContainsKey("Origin"))
                    {
                        _http.Response.Headers.Set("Access-Control-Allow-Origin", "*");
                    }

                    return _next();
                });

            foreach (var _subStartup in _Kernel.GetAll<ISubStartup>())
            {
                app.Map(_subStartup.Path, _subApp => _subStartup.Configuration(_subApp));
            }
        }
开发者ID:VictorBlomberg,项目名称:Farflyg.Server,代码行数:27,代码来源:Startup.cs

示例4: Configuration

        public void Configuration(IAppBuilder app)
        {
            var configuration = new JabbrConfiguration();

            if (configuration.MigrateDatabase)
            {
                // Perform the required migrations
                DoMigrations();
            }

            var kernel = SetupNinject(configuration);

            app.Use(typeof(DetectSchemeHandler));

            if (configuration.RequireHttps)
            {
                app.Use(typeof(RequireHttpsHandler));
            }

            app.UseErrorPage();

            SetupAuth(app, kernel);
            SetupSignalR(kernel, app);
            SetupWebApi(kernel, app);
            SetupMiddleware(kernel, app);
            SetupNancy(kernel, app);

            SetupErrorHandling();
        }
开发者ID:sachin303,项目名称:JabbR,代码行数:29,代码来源:Startup.cs

示例5: MiddlewaresAtDifferentStagesConfiguration

        public void MiddlewaresAtDifferentStagesConfiguration(IAppBuilder app)
        {
            app.Use((context, next) =>
            {
                //Create a custom object in the dictionary to push middlewareIds. 
                context.Set<Stack<int>>("stack", new Stack<int>());
                return next.Invoke();
            });

            var stageTuples = new Tuple<RequestNotification, PipelineStage>[]
                        {
                            new Tuple<RequestNotification, PipelineStage>(RequestNotification.AuthenticateRequest, PipelineStage.Authenticate),
                            new Tuple<RequestNotification, PipelineStage>(RequestNotification.AuthenticateRequest, PipelineStage.PostAuthenticate),
                            new Tuple<RequestNotification, PipelineStage>(RequestNotification.AuthorizeRequest, PipelineStage.Authorize),
                            new Tuple<RequestNotification, PipelineStage>(RequestNotification.AuthorizeRequest, PipelineStage.PostAuthorize),
                            new Tuple<RequestNotification, PipelineStage>(RequestNotification.ResolveRequestCache, PipelineStage.ResolveCache),
                            new Tuple<RequestNotification, PipelineStage>(RequestNotification.ResolveRequestCache, PipelineStage.PostResolveCache),
                            new Tuple<RequestNotification, PipelineStage>(RequestNotification.MapRequestHandler, PipelineStage.MapHandler),
                            new Tuple<RequestNotification, PipelineStage>(RequestNotification.MapRequestHandler, PipelineStage.PostMapHandler),
                            new Tuple<RequestNotification, PipelineStage>(RequestNotification.AcquireRequestState, PipelineStage.AcquireState),
                            new Tuple<RequestNotification, PipelineStage>(RequestNotification.AcquireRequestState, PipelineStage.PostAcquireState),
                            new Tuple<RequestNotification, PipelineStage>(RequestNotification.PreExecuteRequestHandler, PipelineStage.PreHandlerExecute),
                        };

            for (int middlewareId = 0; middlewareId < stageTuples.Length; middlewareId++)
            {
                var stage = stageTuples[middlewareId];
                app.Use<IntegratedPipelineMiddleware>(stage.Item1, middlewareId);
                app.UseStageMarker(stage.Item2);
            }
        }
开发者ID:Xamarui,项目名称:Katana,代码行数:31,代码来源:MiddlewaresAtDifferentStagesTest.cs

示例6: Configuration

        public void Configuration(IAppBuilder builder)
        {
            builder.UseAlpha("a", "b");

            builder.UseFunc(app => Alpha.Invoke(app, "a", "b"));

            builder.UseFunc(Alpha.Invoke, "a", "b");

            builder.Use(Beta.Invoke("a", "b"));

            builder.UseFunc(Beta.Invoke, "a", "b");

            builder.UseGamma("a", "b");

            builder.Use(typeof(Gamma), "a", "b");

            builder.UseType<Gamma>("a", "b");

            builder.UseFunc<AppFunc>(app => new Gamma(app, "a", "b").Invoke);

            builder.Use(typeof(Delta), "a", "b");

            builder.UseType<Delta>("a", "b");

            builder.UseFunc<AppFunc>(app => new Delta(app, "a", "b").Invoke);

            builder.Run(this);
        }
开发者ID:edoc,项目名称:owin-hosting,代码行数:28,代码来源:Startup.cs

示例7: Configuration

        // Invoked once at startup to configure your application.
        public void Configuration(IAppBuilder builder)
        {
			builder.Use((context, next) => { context.Response.Headers.Add("MyHeader", new [] { "abc" }); return next(); });

			builder.UseStaticFiles("/Client");
			//builder.UseFileServer(new FileServerOptions()
			//{
			//	RequestPath = new PathString("/Client"),
			//	FileSystem = new PhysicalFileSystem(".\\Client")
			//});

			builder.Use<BasicAuthentication>();

			HttpConfiguration config = new HttpConfiguration();
			config.Routes.MapHttpRoute("Default", "api/Customer/{customerID}", new { controller="CustomerWebApi", customerID = RouteParameter.Optional });

			var oDataBuilder = new ODataConventionModelBuilder();
			oDataBuilder.EntitySet<Customer>("Customer");
			config.Routes.MapODataRoute("odata", "odata", oDataBuilder.GetEdmModel());

			// Use this if you want XML instead of JSON
			//config.Formatters.XmlFormatter.UseXmlSerializer = true;
			//config.Formatters.Remove(config.Formatters.JsonFormatter);

            config.Formatters.JsonFormatter.UseDataContractJsonSerializer = true;
			//config.Formatters.Remove(config.Formatters.XmlFormatter);

            builder.UseWebApi(config);
		}
开发者ID:mkandroid15,项目名称:Samples,代码行数:30,代码来源:Startup.cs

示例8: Configuration

        public void Configuration(IAppBuilder app)
        {
            // Show an error page
            app.UseErrorPage();

            // Logging component
            app.Use<LoggingComponent>();

            // Configure web api routing
            var config = new HttpConfiguration();
            config.MapHttpAttributeRoutes();
            config.Routes.MapHttpRoute(
                name: "DefaultApi",
                routeTemplate: "api/{controller}/{id}",
                defaults: new { id = RouteParameter.Optional }
            );

            // Use web api middleware
            app.UseWebApi(config);

            // Throw an exception
            app.Use(async (context, next) =>
            {
                if (context.Request.Path.ToString() == "/fail")
                    throw new Exception("Doh!");
                await next();
            });

            // Welcome page
            app.UseWelcomePage("/");
        }
开发者ID:jiantaow,项目名称:AdvDotNet.Samples,代码行数:31,代码来源:Startup.cs

示例9: Configuration

        public void Configuration(IAppBuilder app)
        {
            var httpConfiguration = new HttpConfiguration();

            // Configure Web API Routes:
            // - Enable Attribute Mapping
            // - Enable Default routes at /api.
            httpConfiguration.MapHttpAttributeRoutes();

            httpConfiguration.Routes.MapHttpRoute(
                name: "DefaultApi",
                routeTemplate: "api/{controller}/{action}/{id}",
                defaults: new { id = RouteParameter.Optional },
                constraints: null
            );

            app.Use<SimpleLogger>();
            app.Use<AuthenticationCheck>();

            app.UseWebApi(httpConfiguration);

            // Make ./public the default root of the static files in our Web Application.
            app.UseFileServer(new FileServerOptions
            {
                RequestPath = new PathString(string.Empty),
                FileSystem = new PhysicalFileSystem("./public"),
                EnableDirectoryBrowsing = true,
            });

            app.UseStageMarker(PipelineStage.MapHandler);
        }
开发者ID:pbhughes,项目名称:OGV2_Online,代码行数:31,代码来源:Startup.cs

示例10: Configuration

        public void Configuration(IAppBuilder app)
        {

            //Listando todo o pipeline
            app.Use(async (environment, next) =>
            {
                foreach (var pair in environment.Environment)
                {
                    Console.WriteLine("{0} : {1}", pair.Key, pair.Value);
                }

                await next();
            });

            //Exibindo o que foi requisitado e a resposta
            app.Use(async (environment, next) =>
            {
                Console.WriteLine("Requisição: {0}", environment.Request.Path);
                await next();
                Console.WriteLine("Resposta: {0}", environment.Response.StatusCode);
            });

            app.Run(ctx =>
            {
                return ctx.Response.WriteAsync("Fim!");
            });

        }
开发者ID:fnalin,项目名称:Demos-Asp.net,代码行数:28,代码来源:Program.cs

示例11: CreateLoggerConfiguration

        public void CreateLoggerConfiguration(IAppBuilder app)
        {
            app.SetLoggerFactory(new LoggerFactory());

            app.Use<LoggingMiddleware1>(app);
            app.Use<LoggingMiddleware2>(app);
        }
开发者ID:Xamarui,项目名称:Katana,代码行数:7,代码来源:TracingFacts.cs

示例12: Configuration

        public void Configuration(IAppBuilder app)
        {
            //  app.UseWelcomePage("/");
            //app.Use(new Func<AppFunc, AppFunc>(
            //    next => (
            //        env =>
            //        {
            //            string strText = "原始方式的Owin";
            //            var response = env["owin.ResponseBody"] as Stream;
            //            var responseHeaders = env["owin.ResponseHeader"] as Dictionary<string, string[]>;
            //            responseHeaders.Add("content-type", "text-plain");
            //            return response.WriteAsync(Encoding.UTF8.GetBytes(strText), 0, strText.Length);
            //        }
            //    )));

            app.Use<HelloWorldMiddleware>();

            app.Use<NonebaseMiddleware>();

            app.Use((context, next) => {
                TextWriter output = context.Get<TextWriter>("host.TraceOutput");
                return next().ContinueWith(result =>
                {
                    output.WriteLine("Scheme {0} : Method {1} : Path {2} : MS {3}",
                    context.Request.Scheme, context.Request.Method, context.Request.Path, getTime());
                });
            });

            // 有关如何配置应用程序的详细信息,请访问 http://go.microsoft.com/fwlink/?LinkID=316888
            app.Run(context => {
                context.Response.ContentType = "text/plain";
                return context.Response.WriteAsync("Hello Owin from selfhost!");
            });
        }
开发者ID:McJeremy,项目名称:OwinKatanaTest,代码行数:34,代码来源:Startup1.cs

示例13: Configuration

		public void Configuration(IAppBuilder app)
		{
#if DEBUG
			app.UseErrorPage();
#endif
			
			app.Use(
				async (context, next) =>
				{
					// Log all exceptions and incoming requests
					Console.WriteLine("{0} {1} {2}", context.Request.Method, context.Request.Path, context.Request.QueryString);

					try
					{
						await next();
					}
					catch (Exception exception)
					{
						Console.WriteLine(exception.ToString());
						throw;
					}
				});

			var contentFileSystem = new PhysicalFileSystem("Content");
			app.UseBabel(new BabelFileOptions() { StaticFileOptions = new StaticFileOptions() { FileSystem = contentFileSystem }});
			app.UseFileServer(new FileServerOptions() { FileSystem = contentFileSystem });

			app.Use<CommentsMiddleware>();
		}
开发者ID:RichardD012,项目名称:React.NET,代码行数:29,代码来源:Startup.cs

示例14: Configuration

        public void Configuration(IAppBuilder app)
        {
            var settings = new ApplicationSettings();

            if (settings.MigrateDatabase)
            {
                // Perform the required migrations
                DoMigrations();
            }

            var kernel = SetupNinject(settings);

            app.Use(typeof(DetectSchemeHandler));

            if (settings.RequireHttps)
            {
                app.Use(typeof(RequireHttpsHandler));
            }

            app.UseShowExceptions();

            SetupAuth(app, kernel);
            SetupSignalR(kernel, app);
            SetupWebApi(kernel, app);
            SetupMiddleware(kernel, app, settings);
            SetupNancy(kernel, app);

            SetupErrorHandling();
        }
开发者ID:buybackoff,项目名称:JabbR,代码行数:29,代码来源:Startup.cs

示例15: Configuration

        /// <summary>
        /// The Startup configuration sets up a pipeline with three middleware components, the first two displaying diagnostic information
        /// and the last one responding to events (and also displaying diagnostic information).  The PrintCurrentIntegratedPipelineStage 
        /// method displays the integrated pipeline event this middleware is invoked on and a message.
        /// </summary>
        public void Configuration(IAppBuilder app)
        {
            app.Use((context, next) =>
            {
                PrintCurrentIntegratedPipelineStage(context, "Middleware 1");
                return next.Invoke();
            });
            app.Use((context, next) =>
            {
                PrintCurrentIntegratedPipelineStage(context, "2nd MW");
                return next.Invoke();
            });
            // You can mark OMCs to execute at specific stages of the pipeline by using the IAppBuilder UseStageMarker() extension method.
            // To run a set of middleware components during a particular stage, insert a stage marker right after the last component is the set
            // during registration. There are rules on which stage of the pipeline you can execute middleware and the order components must run
            // (The rules are explained later in the tutorial). Add the UseStageMarker method to the Configuration code as shown below:
            app.UseStageMarker(PipelineStage.Authenticate);

            app.Run(context =>
            {
                PrintCurrentIntegratedPipelineStage(context, "3rd MW");
                return context.Response.WriteAsync("Hello world");
            });
            app.UseStageMarker(PipelineStage.ResolveCache);
        }
开发者ID:TheFastCat,项目名称:OWINKatanaExamples,代码行数:30,代码来源:Startup.cs


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