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


C# IApplicationBuilder.MapWhen方法代码示例

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


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

示例1: Configure

        public void Configure(IApplicationBuilder app, CommonService service)
        {
            var authOptions = new CookieAuthenticationOptions {
                AuthenticationScheme = CookieAuthenticationDefaults.AuthenticationScheme,
                AutomaticAuthenticate = true,
                AutomaticChallenge = true,
                ExpireTimeSpan = TimeSpan.FromHours(5),
                Events = new CookieAuthenticationEvents {
                    OnRedirectToLogin = context => {
                        context.Response.StatusCode = (int) HttpStatusCode.Unauthorized;
                        return Task.CompletedTask;
                    }
                }
            };

            // redirect to setup until configured
            app.MapWhen(
                ctx => ctx.Request.Path == "/" && !service.IsConfigured(),
                req => req.Run(
                    ctx => Task.Run(() => ctx.Response.Redirect("/setup"))
                )
            );
            app.UseDefaultFiles()
                .UseStaticFiles()
                .UseCookieAuthentication(authOptions)
                .UseMvc();
            CreateDatabase(app);
        }
开发者ID:proog,项目名称:g_,代码行数:28,代码来源:Startup.cs

示例2: Configure

        public void Configure(IApplicationBuilder app, ILoggerFactory logger)
        {
            logger.AddConsole(LogLevel.Information);

            app.UseHttpLog();

            app.UseDeveloperExceptionPage();
            app.UseStaticFiles();
            app.UseMvc();

            app.MapWhen(ctx => ctx.Request.Path.Value.Equals("/super-secret"), HandleSecret);

            app.Use(async (context, next) =>
            {
                Console.WriteLine("1");
                await next.Invoke();
                Console.WriteLine("2");
            });

            app.Use(async (context, next) =>
            {
                Console.WriteLine("3");
                await next.Invoke();
                Console.WriteLine("4");
            });

            app.Run(async (context) =>
            {
                //throw new Exception("Something bad happened...");
                await context.Response.WriteAsync(_configuration.Get<string>("HelloMessage"));
            });
        }
开发者ID:rjovic,项目名称:ATD11,代码行数:32,代码来源:Startup.cs

示例3: Configure

        public void Configure(IApplicationBuilder app, ILoggerFactory loggerFactory)
        {
            loggerFactory.MinimumLevel = LogLevel.Information;
            loggerFactory.AddConsole();

            app.MapWhen(ctx => ctx.Request.Path.Equals("/api/qrcode") && ctx.Request.Method.Equals("GET"), HandleQRCode);
            app.Run(async (context) =>
            {
                context.Response.StatusCode = StatusCodes.Status400BadRequest;
                await context.Response.WriteAsync("usage:  /api/qrcode?text=yourtext");                
            });
        }
开发者ID:r15h1,项目名称:qrcodr,代码行数:12,代码来源:Startup.cs

示例4: Configure

        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
        {
            //
            // Scenarios:
            // 1. Multiple services.
            // 2. Various versions or kinds of clients side by side.
            //

            //
            // SMS
            //
            app.Map("/sms",
                subApp =>
                {
                    subApp.RunGateway(new GatewayOptions() { ServiceDescription = new SmsServiceDescription() });
                }
            );

            //
            // Counter
            //
            app.Map("/counter",
                subApp =>
                {
                    subApp.RunGateway(new GatewayOptions() { ServiceDescription = new CounterServiceDescription() });
                }
            );

            app.Map("/Hosting/CounterService",
                subApp =>
                {
                    subApp.RunGateway(new GatewayOptions() { ServiceDescription = new CounterServiceDescription() });
                }
            );

            app.MapWhen(
                context =>
                {
                    StringValues serviceNames;

                    return context.Request.Headers.TryGetValue("SF-ServiceName", out serviceNames) &&
                           serviceNames.Count == 1 &&
                           serviceNames[0] == "fabric:/Hosting/CounterService";
                },
                subApp =>
                {
                    subApp.RunGateway(new GatewayOptions() { ServiceDescription = new CounterServiceDescription() });
                }
            );
        }
开发者ID:IllyriadGames,项目名称:Hosting,代码行数:51,代码来源:Startup.cs

示例5: Configure

        public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
        {
            loggerFactory.MinimumLevel = LogLevel.Information;
            loggerFactory.AddConsole(minLevel: LogLevel.Information);
            loggerFactory.AddDebug();

            var logger = loggerFactory.CreateLogger(env.EnvironmentName);

            app.UseRequestLogger();

            app.MapWhen(context =>
            {
                return context.Request.Query.ContainsKey("branch");
            }, HandleBranch);

            app.Run(async context =>
            {
                context.Response.ContentType = "text/plain";

                await context.Response.WriteAsync("Hello from " + env.EnvironmentName);
            });
        }
开发者ID:serveryang,项目名称:UniformUIKit,代码行数:22,代码来源:Startup.cs

示例6: Configure

        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, 
            IHostingEnvironment env)
        {
            app.UseIISPlatformHandler();

            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            app.UseStatusCodePagesWithReExecute("/errors/{0}");

            app.MapWhen(context => context.Request.Path == "/missingpage", builder => { });

            // "/errors/400"
            app.Map("/errors", error =>
            {
                error.Run(async context =>
                {
                    var builder = new StringBuilder();
                    builder.AppendLine("<html><body>");
                    builder.AppendLine("An error occurred, Status Code: " + 
                        HtmlEncoder.Default.HtmlEncode(context.Request.Path.ToString().Substring(1)) + "<br />");
                    var referrer = context.Request.Headers["referer"];
                    if (!string.IsNullOrEmpty(referrer))
                    {
                        builder.AppendLine("Return to <a href=\"" + HtmlEncoder.Default.HtmlEncode(referrer) + "\">" + 
                            WebUtility.HtmlEncode(referrer) + "</a><br />");
                    }
                    builder.AppendLine("</body></html>");
                    context.Response.ContentType = "text/html";
                    await context.Response.WriteAsync(builder.ToString());
                });
            });

            HomePage(app);
        }
开发者ID:ChujianA,项目名称:aspnetcore-doc-cn,代码行数:37,代码来源:Startup.cs

示例7: Configure_Map2

 public void Configure_Map2(IApplicationBuilder app)
 {
     app.MapWhen(c => c.Request.Query["k"] == "1", a => a.Run(async c => await Dump(c.Response.Body, c.Request)));
     app.MapWhen(c => c.Request.Query["k"] == "2", a => a.Run(async c => await Dump(c.Response.Body, c.Response)));
     app.MapWhen(c => c.Request.Query["k"] == "3", a => a.Run(async c => await Dump(c.Response.Body, c)));
 }
开发者ID:pakrym,项目名称:signoffs,代码行数:6,代码来源:Startup.cs

示例8: Configure

        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, ILoggerFactory loggerFactory)
        {
            app.UseStaticFiles();
            loggerFactory.AddConsole();
            loggerFactory.AddDebug();

            // loggerFactory.AddConsole(Configuration.GetSection("Logging"));
            //loggerFactory.AddConsole();
            // loggerFactory.AddDebug();




            app.UseSession();
            // uncomment these lines to use the Middleware sample
            // app.UseHeaderMiddleware();
            // app.UseHeading1Middleware();


            app.Map("/home2", homeApp =>
            {
                homeApp.Run(async context =>
                {
                    HomeController controller =
                      app.ApplicationServices.GetService<HomeController>();
                    int statusCode = await controller.Index(context);
                    context.Response.StatusCode = statusCode;
                });
            });

            app.Map("/session", sessionApp =>
            {
                sessionApp.Run(async context =>
                {
                    await SessionSample.SessionAsync(context);
                });
            });

            PathString remaining;
            app.MapWhen(context => context.Request.Path.StartsWithSegments("/configuration", out remaining),
                configApp =>
                {
                    configApp.Run(async context =>
                    {
                        if (remaining.StartsWithSegments("/appsettings"))
                        {
                            await ConfigSample.AppSettings(context, Configuration);
                        }
                        else if (remaining.StartsWithSegments("/database"))
                        {
                            await ConfigSample.ReadDatabaseConnection(context, Configuration);
                        }
                        else if (remaining.StartsWithSegments("/secret"))
                        {
                            await ConfigSample.UserSecret(context, Configuration);
                        }
                    });
                });


            app.Map("/configuration", configApp =>
            {
                configApp.Run(async context =>
                {
                    await ConfigSample.ReadDatabaseConnection(context, Configuration);
                });
            });

            //// uncomment this app.Run invocation to active the Hello, World! output
            //app.Run(async (context) =>
            //{
            //    await context.Response.WriteAsync("Hello World!");
            //});

            //// uncomment this app.Run invocation for the first Request and Response sample
            //app.Run(async (context) =>
            //{
            //    await context.Response.WriteAsync(RequestAndResponseSample.GetRequestInformation(context.Request));
            //});


            //// uncomment this app.Run invocation for the custom routing
            //app.Run(async (context) =>
            //{
            //    if (context.Request.Path.Value.ToLower() == "/home")
            //    {
            //        HomeController controller =
            //          app.ApplicationServices.GetService<HomeController>();
            //        int statusCode = await controller.Index(context);
            //        context.Response.StatusCode = statusCode;
            //        return;
            //    }
            //}

            //// uncomment this app.Run invocation for request/response samples
            //app.Run(async (context) =>
            //{
            //    string result = string.Empty;
            //    switch (context.Request.Path.Value.ToLower())
//.........这里部分代码省略.........
开发者ID:ProfessionalCSharp,项目名称:ProfessionalCSharp6,代码行数:101,代码来源:Startup.cs

示例9: Configure

        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, 
            ILoggerFactory loggerFactory)
        {
            loggerFactory.AddConsole(Configuration.GetSection("Logging"));
            loggerFactory.AddDebug();

            app.UseDeveloperExceptionPage();

            // ...

            app.UseMyMiddleware();

            // ...

            app.UseMyMiddlewareWithParams();

            var myMiddlewareOptions = 
                Configuration.Get<MyMiddlewareOptions>("MyMiddlewareOptionsSection");

            var myMiddlewareOptions2 = 
                Configuration.Get<MyMiddlewareOptions>("MyMiddlewareOptionsSection2");

            app.UseMyMiddlewareWithParams(myMiddlewareOptions);

            // ...

            app.UseMyMiddlewareWithParams(myMiddlewareOptions2);

            app.UseMyTerminatingMiddleware();

            app.UseIISPlatformHandler();

            

            // Create branch to the MyHandlerMiddleware. 
            // All requests ending in .report will follow this branch.
            app.MapWhen(
                context => context.Request.Path.ToString().EndsWith(".report"),
                appBranch => {
                    // ... optionally add more middleware to this branch
                    appBranch.UseMyHandler();
                });

            app.MapWhen(
                context => context.Request.Path.ToString().EndsWith(".context"),
                appBranch => {
                    appBranch.UseHttpContextDemoMiddleware();
                });

            

            app.UseStaticFiles();

            app.UseMvc(routes =>
            {
                routes.MapRoute(
                    name: "default",
                    template: "{controller=Home}/{action=Index}/{id?}");
            });
        }
开发者ID:ChujianA,项目名称:aspnetcore-doc-cn,代码行数:61,代码来源:Startup.cs

示例10: ConfigureMapWhen

        public void ConfigureMapWhen(IApplicationBuilder app)
        {
            app.MapWhen(context => {
                return context.Request.Query.ContainsKey("branch");
            }, HandleBranch);

            app.Run(async context =>
            {
                await context.Response.WriteAsync("Hello from " + _environment);
            });
        }
开发者ID:bigfont,项目名称:Docs,代码行数:11,代码来源:Startup.cs

示例11: Configure

        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
        {
            app.UseCors("AllowAll");

            loggerFactory.AddConsole(Configuration.GetSection("Logging"));
            loggerFactory.AddDebug();

            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
                app.UseBrowserLink();
            }
            else
            {
                app.UseExceptionHandler("/Home/Error");
            }

            app.UseCookieAuthentication(new CookieAuthenticationOptions()
            {
                AuthenticationScheme = Startup.AuthenticationScheme,
                CookieName = "KrosbookAuth",
                AutomaticAuthenticate = true,
                AutomaticChallenge = true,
                SlidingExpiration = true,
                ExpireTimeSpan = TimeSpan.FromHours(8),
                LoginPath = new PathString("/login"),
                AccessDeniedPath = new PathString("/login"),
                CookieHttpOnly = true //ak je false tak mozno editovat cookie v prehliadaci
            });

            app.UseStaticFiles();

            app.UseIdentity();

            app.UseMvc();

            app.MapWhen(context =>
            {
                var requestPath = context.Request.Path.Value;

                return !(Path.HasExtension(requestPath) && requestPath.Contains("/api/"));
            },
            branch =>
            {
                branch.Use((context, next) =>
                {
                    context.Request.Path = new PathString("/index.html");
                    return next();
                });

                branch.UseStaticFiles();
            });

            DbInitializer.Initialize(app.ApplicationServices);
        }
开发者ID:FunnyBean,项目名称:Krosbook,代码行数:56,代码来源:Startup.cs

示例12: Configure

        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, ILoggerFactory loggerFactory)
        {
            app.UseIISPlatformHandler();
            app.UseStaticFiles();
            loggerFactory.AddConsole();
            loggerFactory.AddDebug();

            // loggerFactory.AddConsole(Configuration.GetSection("Logging"));
            //loggerFactory.AddConsole();
            // loggerFactory.AddDebug();




            app.UseSession();
            //// uncomment these lines to use the Middleware sample
            //app.UseHeaderMiddleware();
            //app.UseHeading1Middleware();


            app.Map("/home2", homeApp =>
            {
                homeApp.Run(async context =>
                {
                    HomeController controller =
                      app.ApplicationServices.GetService<HomeController>();
                    int statusCode = await controller.Index(context);
                    context.Response.StatusCode = statusCode;
                });
            });

            app.Map("/session", sessionApp =>
            {
                sessionApp.Run(async context =>
                {
                    await SessionSample.SessionAsync(context);
                });
            });

            PathString remaining;
            app.MapWhen(context => context.Request.Path.StartsWithSegments("/configuration", out remaining),
                configApp =>
                {
                    configApp.Run(async context =>
                    {
                        if (remaining.StartsWithSegments("/appsettings"))
                        {
                            await ConfigSample.AppSettings(context, Configuration);
                        }
                        else if (remaining.StartsWithSegments("/database"))
                        {
                            await ConfigSample.ReadDatabaseConnection(context, Configuration);
                        }
                        else if (remaining.StartsWithSegments("/secret"))
                        {
                            await ConfigSample.UserSecret(context, Configuration);
                        }
                    });
                });


            app.Map("/configuration", configApp =>
            {
                configApp.Run(async context =>
                {
                    await ConfigSample.ReadDatabaseConnection(context, Configuration);
                });
            });

            //// uncomment this app.Run invocation to active the Hello, World!output
            //app.Run(async (context) =>
            //{
            //    await context.Response.WriteAsync("Hello World!");
            //});

            //// uncomment this app.Run invocation for the first Request and Response sample
            //app.Run(async (context) =>
            //{
            //    await context.Response.WriteAsync(RequestAndResponseSample.GetRequestInformation(context.Request));
            //});


            //// uncomment this app.Run invocation for the custom routing
            //app.Run(async (context) =>
            //{
            //    if (context.Request.Path.Value.ToLower() == "/home")
            //    {
            //        HomeController controller =
            //          app.ApplicationServices.GetService<HomeController>();
            //        int statusCode = await controller.Index(context);
            //        context.Response.StatusCode = statusCode;
            //        return;
            //    }

            //    string result = string.Empty;
            //    switch (context.Request.Path.Value.ToLower())
            //    {
            //        case "/header":
            //            result = RequestAndResponseSample.GetHeaderInformation(context.Request);
//.........这里部分代码省略.........
开发者ID:CNinnovation,项目名称:TechConference2016,代码行数:101,代码来源:Startup.cs

示例13: Configure

        bool IsTimingOn = true; // we would want this to be config, but that's another demo!

        #endregion Fields

        #region Methods

        public void Configure(IApplicationBuilder app)
        {
            app
                .MapWhen((context) => context.Request.Headers.ContainsKey("X-Request-Timing"), ConfigureTimedApi)
                .Map("/api", ConfigureApi)
                .Map("", ConfigureWeb);
        }
开发者ID:rleopold,项目名称:AspPipelineDemo,代码行数:13,代码来源:Startup.cs


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