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


C# IApplicationBuilder.Run方法代码示例

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


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

示例1: Configure

        public void Configure(IApplicationBuilder app)
        {
            app.Run(async context =>
            {
                await context.Response.WriteAsync("Hello, World!");
            });

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

示例2: Configure

        public void Configure(IApplicationBuilder app, ILoggerFactory factory)
        {
            app.UseElmPage(); // Shows the logs at the specified path
            app.UseElmCapture(); // Adds the ElmLoggerProvider

            var logger = factory.CreateLogger<Startup>();
            using (logger.BeginScope("startup"))
            {
                logger.LogWarning("Starting up");
            }

            app.Run(async context =>
            {
                await context.Response.WriteAsync("Hello world");
                using (logger.BeginScope("world"))
                {
                    logger.LogInformation("Hello world!");
                    logger.LogError("Mort");
                }
                // This will not get logged because the filter has been set to LogLevel.Information and above
                using (logger.BeginScope("debug"))
                {
                    logger.LogDebug("some debug stuff");
                }
            });
            logger.LogInformation("This message is not in a scope");
        }
开发者ID:leloulight,项目名称:Entropy,代码行数:27,代码来源:Startup.cs

示例3: Configure

 public void Configure(IApplicationBuilder app)
 {
     app.Run(context =>
     {
         return context.Response.WriteAsync("Hello PriyaLaksmi");
     });
 }
开发者ID:Rajakani,项目名称:CoreApp,代码行数:7,代码来源:Startup.cs

示例4: Configure

 public void Configure(IApplicationBuilder app)
 {
     app.UseIISPlatformHandler();
     
     app.Run(async context =>
     {
         var singleton1 = context.RequestServices.GetService<ISingleton>();
         var singleton2 = context.RequestServices.GetService<ISingleton>();
         var scoped1 = context.RequestServices.GetService<IScoped>();
         var scoped2 = context.RequestServices.GetService<IScoped>();
         var transient1 = context.RequestServices.GetService<ITransient>();
         var transient2 = context.RequestServices.GetService<ITransient>();
         var instance1 = context.RequestServices.GetService<IInstance>();
         var instance2 = context.RequestServices.GetService<IInstance>();
         
         await context.Response.WriteAsync(
             "<table>" +
             $"<tr><td>Singleton 1 and Singleton 2 are the same instance:</td><td> {object.ReferenceEquals(singleton1, singleton2)}</td></tr>" +
             $"<tr><td>Instance 1 and Instance 2 are the same instance:</td><td> {object.ReferenceEquals(instance1, instance2)}</td></tr>" +
             $"<tr><td>Scoped 1 and Scoped 2 are the same instance:</td><td> {object.ReferenceEquals(scoped1, scoped2)}</td></tr>" +
             $"<tr><td>Transient 1 and Transient 2 are the same instance:</td><td> {object.ReferenceEquals(transient1, transient2)}</td></tr>" +
             "</table><br><br><table>" +
             $"<tr><td>Singleton Id:</td><td> {singleton1.Id}</td></tr>" +
             $"<tr><td>Instance Id:</td><td> {instance1.Id}</td></tr>" +
             $"<tr><td>_instanceId:</td><td> {InstanceId}</td></tr>" +
             $"<tr><td>Scoped Id:</td><td> {scoped1.Id}</td></tr>" +
             $"<tr><td>Transient 1 Id:</td><td> {transient1.Id}</td></tr>" +
             $"<tr><td>Transient 2 Id:</td><td> {transient2.Id}</td></tr>" +
             "</table>");
     });
 }
开发者ID:jeffogata,项目名称:aspnet-di-03-vs,代码行数:31,代码来源:Startup.cs

示例5: Configure

 public void Configure(IApplicationBuilder app)
 {
     app.Run(async (context) =>
     {
         await context.Response.WriteAsync("Hello Shaun and Anthony!");
     });
 }
开发者ID:bigfont,项目名称:asp-net-core-vnow,代码行数:7,代码来源: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, ILoggerFactory loggerFactory)
 {
     app.Run(async (context) =>
     {
         await context.Response.WriteAsync("Hello World!");
     });
 }
开发者ID:DanWahlin,项目名称:ASP.NET5Demos,代码行数:8,代码来源:Startup.cs

示例7: Configure

 public void Configure(IApplicationBuilder app)
 {
     app.Run(async (context) =>
     {
         await context.Response.WriteAsync("Hello World via " + ((IServerInformation)app.Server).Name + "!");
     });
 }
开发者ID:dvincent,项目名称:Docs,代码行数:7,代码来源: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)
        {
            app.UseDefaultFiles();
            app.UseStaticFiles();

            app.Run(ProcessRequest);
        }
开发者ID:hultqvist,项目名称:lax,代码行数:8,代码来源:Startup.cs

示例9: Configure

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

            app.UseCookieAuthentication(options =>
            {
                options.AutomaticAuthentication = true;
                options.SessionStore = new MemoryCacheSessionStore();
            });

            app.Run(async context =>
            {
                if (!context.User.Identities.Any(identity => identity.IsAuthenticated))
                {
                    // Make a large identity
                    var claims = new List<Claim>(1001);
                    claims.Add(new Claim(ClaimTypes.Name, "bob"));
                    for (int i = 0; i < 1000; i++)
                    {
                        claims.Add(new Claim(ClaimTypes.Role, "SomeRandomGroup" + i, ClaimValueTypes.String, "IssuedByBob", "OriginalIssuerJoe"));
                    }

                    await context.Authentication.SignInAsync(CookieAuthenticationDefaults.AuthenticationScheme,
                        new ClaimsPrincipal(new ClaimsIdentity(claims, CookieAuthenticationDefaults.AuthenticationScheme)));

                    context.Response.ContentType = "text/plain";
                    await context.Response.WriteAsync("Hello First timer");
                    return;
                }

                context.Response.ContentType = "text/plain";
                await context.Response.WriteAsync("Hello old timer");
            });
        }
开发者ID:jmloeffler,项目名称:Security,代码行数:34,代码来源:Startup.cs

示例10: Configure

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

            app.UseIISPlatformHandler();

            app.UseCookieAuthentication(options =>
            {
                options.AutomaticAuthenticate = true;
            });

            app.UseOpenIdConnectAuthentication(options =>
            {
                options.ClientId = "63a87a83-64b9-4ac1-b2c5-092126f8474f";
                options.ClientSecret = "Yse2iP7tO1Azq0iDajNisMaTSnIDv+FXmAsFuXr+Cy8="; // for code flow
                options.Authority = "https://login.windows.net/tratcheroutlook.onmicrosoft.com";
                options.ResponseType = OpenIdConnectResponseTypes.Code;
                options.GetClaimsFromUserInfoEndpoint = true;
            });

            app.Run(async context =>
            {
                if (!context.User.Identities.Any(identity => identity.IsAuthenticated))
                {
                    await context.Authentication.ChallengeAsync(OpenIdConnectDefaults.AuthenticationScheme, new AuthenticationProperties { RedirectUri = "/" });

                    context.Response.ContentType = "text/plain";
                    await context.Response.WriteAsync("Hello First timer");
                    return;
                }

                context.Response.ContentType = "text/plain";
                await context.Response.WriteAsync("Hello Authenticated User");
            });
        }
开发者ID:leloulight,项目名称:Security,代码行数:35,代码来源:Startup.cs

示例11: Configure

        public void Configure(IApplicationBuilder app, ILoggerFactory loggerFactory)
        {
            loggerFactory.AddDebug();

            app.UseApplicationInsightsRequestTelemetry();

            app.UseApplicationInsightsExceptionTelemetry();

            app.UseErrorHandler(a =>
            {
                a.UseMiddleware<ErrorMiddleware>();
            });

            app.UseWelcomePage("/welcome");
            app.UseRuntimeInfoPage("/runtimeinfo");


            //app.UseErrorPage();


            app.Run(async (context) =>
            {
                if (context.Request.Query.ContainsKey("throw"))
                    throw new AggregateException("Some funny exception, 42");

                await context.Response.WriteAsync("Hello World!");
            });            
        }
开发者ID:rafsan,项目名称:Cancel,代码行数:28,代码来源:Startup.cs

示例12: Configure

        public void Configure(IApplicationBuilder app, IHostingEnvironment env)
        {
            if (string.Equals(env.EnvironmentName, "Development", StringComparison.OrdinalIgnoreCase))
            {
                app.UseDeveloperExceptionPage();

                app.UseRuntimeInfoPage(); // default path is /runtimeinfo
            }
            else
            {
                // specify production behavior for error handling, for example:
                // app.UseExceptionHandler("/Home/Error");
                // if nothing is set here, exception will not be handled.
            }

            app.UseWelcomePage("/welcome");

            app.Run(async (context) =>
            {
                if(context.Request.Query.ContainsKey("throw")) throw new Exception("Exception triggered!");
                context.Response.ContentType = "text/html";
                await context.Response.WriteAsync("<html><body>Hello World!");
                await context.Response.WriteAsync("<ul>");
                await context.Response.WriteAsync("<li><a href=\"/welcome\">Welcome Page</a></li>");
                await context.Response.WriteAsync("<li><a href=\"/?throw=true\">Throw Exception</a></li>");
                await context.Response.WriteAsync("</ul>");
                await context.Response.WriteAsync("</body></html>");
            });
        }
开发者ID:dvincent,项目名称:Docs,代码行数:29,代码来源:Startup.cs

示例13: Configure

 // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
 public void Configure(IApplicationBuilder app)
 {
     app.Run(async (context) =>
     {
         await context.Response.WriteAsync("I'm running on shared framework from: " +typeof(object).GetTypeInfo().Assembly.Location);
     });
 }
开发者ID:pakrym,项目名称:signoffs,代码行数:8,代码来源:Startup.cs

示例14: Configure

        public void Configure(IApplicationBuilder app)
        {
            app.UseOwin(addToPiepline =>
            {
                addToPiepline(next =>
                {
                    return async env =>
                    {
                        var accept = env["websocket.Accept"] as WebSocketAccept;
                        if (accept == null)
                        {
                            // Not a websocket request
                            await next(env);
                        }
                        else
                        {
                            accept(null, WebSocketEcho);
                        }
                    };
                });
            });

            app.Run(async context =>
            {
                context.Response.ContentType = "text/plain";
                await context.Response.WriteAsync("Not a WebSocket");
            });
        }
开发者ID:transformersprimeabcxyz,项目名称:_TO-DO-Entropy-aspnet,代码行数:28,代码来源:Startup.cs

示例15: Configure

        public void Configure(IApplicationBuilder app)
        {
            app.Run((RequestDelegate)(async context =>
            {
                var singleton1 = context.RequestServices.GetService<ISingletonService>();
                var singleton2 = context.RequestServices.GetService<ISingletonService>();
                
                var scoped1 = context.RequestServices.GetService<IScopedService>();
                var scoped2 = context.RequestServices.GetService<IScopedService>();
                
                var transient1 = context.RequestServices.GetService<ITransientService>();
                var transient2 = context.RequestServices.GetService<ITransientService>();

                await context.Response.WriteAsync(
                    "<html><body><strong>Autofac</strong><br><br>" +
                    $"ReferenceEquals(singleton1, singleton2): {object.ReferenceEquals(singleton1, singleton2)}<br>" +
                    $"ReferenceEquals(scoped1, scoped2): {object.ReferenceEquals(scoped1, scoped2)}<br>" +
                    $"ReferenceEquals(transient1, transient2): {object.ReferenceEquals(transient1, transient2)}<br><br>" +
                    $"Singleton Id: {singleton1.Id}, Created: {singleton1.Created}, OtherService: {singleton1.OtherService.Id}<br><br>" +
                    $"Scoped Id: {scoped1.Id}, Created: {scoped1.Created}, OtherService: {scoped1?.OtherService.Id}<br><br>" +
                    $"Transient 1 Id: {transient1.Id}, Created: {transient1.Created}, OtherService: {transient1.OtherService.Id}<br>" +
                    $"Transient 2 Id: {transient2.Id}, Created: {transient2.Created}, OtherService: {transient2.OtherService.Id}" +
                    "</body></html>");
            }));
        }
开发者ID:jeffogata,项目名称:aspnet-di-03-cli,代码行数:25,代码来源:Startup.cs


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