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


C# IAppBuilder.Run方法代码示例

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


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

示例1: Configuration

        public void Configuration(IAppBuilder app)
        {
            if (!HasNoSecurityConfigured())
            {
                Trace.TraceInformation("Using AAD middleware");

                string audience = _configurationService.Get("ida.Audience");
                string tenant = _configurationService.Get("ida.Tenant");
                string aadInstance = _configurationService.Get("ida.AADInstance");

                string metadataAddress = string.Format(aadInstance, tenant) + "/federationmetadata/2007-06/federationmetadata.xml";

                app.UseWindowsAzureActiveDirectoryBearerAuthentication(new WindowsAzureActiveDirectoryBearerAuthenticationOptions
                {
                    TokenValidationParameters = new TokenValidationParameters
                    {
                        SaveSigninToken = true,
                        ValidAudience = audience,
                        ValidateIssuer = true,
                        IssuerValidator = (string issuer, SecurityToken securityToken, TokenValidationParameters validationParameters) => { return issuer; }
                    },
                    Tenant = tenant,
                    MetadataAddress = metadataAddress
                });
            }

            Initialize();

            app.Run(Invoke);
        }
开发者ID:jinujoseph,项目名称:NuGet.Services.Metadata,代码行数:30,代码来源:Startup.cs

示例2: 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

示例3: Configuration

 public void Configuration(IAppBuilder app)
 {
     app.Run(context =>
         {
             return context.Response.WriteAsync(RESULT);
         });
 }
开发者ID:Xamarui,项目名称:Katana,代码行数:7,代码来源:DiscoveryTests.cs

示例4: Configuration

        public void Configuration(IAppBuilder app)
        {
            app.Run(context =>
            {
                Stopwatch stopWatch = new Stopwatch();
                Trace.WriteLine("Received client call. Starting stop watch now.");
                stopWatch.Start();

                context.Request.CallCancelled.Register(() =>
                {
                    stopWatch.Stop();
                    Trace.WriteLine(string.Format("Cancellation token triggered. Elapsed time : {0}. Test should succeed", stopWatch.Elapsed));
                    NotificationServer.NotifyClient();
                });

                int retryCount = 0;
                while (retryCount < 3)
                {
                    Thread.CurrentThread.Join(5 * 1000);
                    if (context.Request.CallCancelled.IsCancellationRequested)
                    {
                        break;
                    }
                    retryCount++;
                }

                return context.Response.WriteAsync("FAILURE");
            });
        }
开发者ID:Xamarui,项目名称:Katana,代码行数:29,代码来源:OwinCallCancelledTest.cs

示例5: GoogleOAuth2Configuration

        public void GoogleOAuth2Configuration(IAppBuilder app)
        {
            app.UseAuthSignInCookie();

            var option = new GoogleOAuth2AuthenticationOptions()
            {
                ClientId = "581497791735.apps.googleusercontent.com",
                ClientSecret = "-N8rQkJ_MKbhpaxyjdVYbFpO",
            };

            app.UseGoogleAuthentication(option);

            app.Run(async context =>
                {
                    if (context.Authentication.User == null || !context.Authentication.User.Identity.IsAuthenticated)
                    {
                        var authenticationProperties = new AuthenticationProperties();
                        authenticationProperties.Dictionary.Add("access_type", "custom_accessType");
                        authenticationProperties.Dictionary.Add("approval_prompt", "custom_approval_prompt");
                        authenticationProperties.Dictionary.Add("login_hint", "custom_login_hint");

                        context.Authentication.Challenge(authenticationProperties, "Google");
                        await context.Response.WriteAsync("Unauthorized");
                    }
                });
        }
开发者ID:Xamarui,项目名称:Katana,代码行数:26,代码来源:GoogleOAuth2AuthorizeParameters.cs

示例6: Configuration

        public void Configuration(IAppBuilder app)
        {
            //app.UseErrorPage();
            //app.UseWelcomePage();

            // Configure Web API for self-host.
            HttpConfiguration config = new HttpConfiguration();
            config.MapHttpAttributeRoutes();
            config.Formatters.Remove(config.Formatters.XmlFormatter);
            app.UseWebApi(config);

            app.Run(async (context) =>  // IOWinContext
            {
                context.Response.StatusCode = 200;
                context.Response.ContentType = "text/html";

                string header = "<html><body><h1>Selfhost Vars</h1>";
                await context.Response.WriteAsync(header);

                foreach (KeyValuePair<string, object> keyvalue in context.Environment)
                {
                    if (keyvalue.Value == null)
                        continue;

                    string t = keyvalue.Key + ":  " + keyvalue.Value.ToString() + "<hr />\r\n";

                    await context.Response.WriteAsync(t);
                    //await Task.Delay(1000);  // no output buffering - text just goes
                }

                await context.Response.WriteAsync("</body></html>");
            });
        }
开发者ID:RickStrahl,项目名称:AspNetFrameworksPerformance,代码行数:33,代码来源:Startup.cs

示例7: BuildSample

        public static void BuildSample(IAppBuilder app)
        {
            // add eventsource middleware
            app.EventSource(envKey);
            app.Run(context => {

                // get the event stream (not captured yet)
                var eventStream = context.Environment[envKey] as IEventStream;

                // create some timers to send mesages
                var timer = new System.Threading.Timer(_ => {
                    var ts = DateTime.UtcNow.ToString("O");
                    eventStream.WriteAsync("Timer1:" + ts + message + "\n");
                }, null, 1,  50);
                var timer2 = new System.Threading.Timer(_ => {
                    var ts = DateTime.UtcNow.ToString("O");
                    eventStream.WriteAsync("Timer 2:" + ts + "\n");
                }, null, 1,  25);

                // Capture the eventstream by calling Open and pass in the 
                // clean-up logic for when this client closes the stream
                var task =  eventStream.Open(() => {
                    Console.WriteLine("Closed");
                    timer.Dispose();
                    timer2.Dispose();
                });

                eventStream.WriteAsync("Started\n");
                return task;
            });
        }
开发者ID:Xamarui,项目名称:OwinUtils,代码行数:31,代码来源:EventSourceSample.cs

示例8: Configuration

        public void Configuration(IAppBuilder app)
        {
            app.UseWelcomePage(new PathString("/Welcome"));

            app.UseFileServer(new FileServerOptions
            {
                EnableDirectoryBrowsing = false,
                FileSystem = new PhysicalFileSystem(@"..\..\..\KatanaApp\StaticResources"),
                RequestPath = new PathString(@"/contents")
            });

            app.Run(ctx =>
            {
                if (string.IsNullOrEmpty(ctx.Request.Path.Value) || ctx.Request.Path.Value == "/" || ctx.Request.Path.Value == "/Welcome/")
                {
                    ctx.Response.Redirect("/app/Welcome");
                }
                // New code: Throw an exception for this URI path.
                if (ctx.Request.Path.Value == @"/fail")
                {
                    throw new HttpException(500, "Random exception");
                }
                ctx.Response.ContentType = "text/plain";
                return ctx.Response.WriteAsync("Hello World!");
            });
        }
开发者ID:naingyelin,项目名称:GettingStartedWithKatana,代码行数:26,代码来源:StartupProduction.cs

示例9: Configuration

        public void Configuration(IAppBuilder app)
        {
            var db = new ApplicationDbContext();
            var userManager = new UserManager<User, int>(new UserStore(db));
            var roleManager = new RoleManager<UserRole, int>(new RoleStore(db));

            var sb = new StringBuilder();

            var format = "{0, -3} | {1, -15} | {2, -30} | {3, -20}";
            sb.AppendLine("ASP.NET Identity Users:\n");
            sb.AppendLine(string.Format(format, "ID", "Username", "Email", "Role(s)"));
            sb.AppendLine("-----------------------------------------------------------------------------");

            foreach (var user in userManager.Users.Include(u => u.Roles))
            {
                sb.AppendLine(string.Format(format, user.Id, user.UserName, user.Email, string.Join(", ", user.Roles.Select(r => r.Name).ToArray())));
            }

            sb.AppendLine("\n\nASP.NET Identity Roles:\n");
            format = "{0, -3} | {1, -20}";
            sb.AppendLine(string.Format(format, "ID", "Role"));
            sb.AppendLine("--------------------------");

            foreach (var role in roleManager.Roles)
            {
                sb.AppendLine(string.Format(format, role.Id, role.Name));
            }

            app.Run(context =>
            {
                context.Response.ContentType = "text/plain";
                return context.Response.WriteAsync(sb.ToString());
            });
        }
开发者ID:nsallman,项目名称:AspNet.Identity,代码行数:34,代码来源:Startup.cs

示例10: Configuration

        public void Configuration(IAppBuilder app)
        {
            app.Run(async context =>
            {
                if (context.Request.Method == "POST" && context.Request.Path.Value == "/start")
                {
                    Console.WriteLine("Start...");
                }
                else if (context.Request.Method == "GET" && context.Request.Path.Value == "/move")
                {
                    var random = new Random();
                    var moves = new string[] { "ROCK", "PAPER", "SCISSORS" };
                    var move = moves[random.Next(0, moves.Length)];
                    context.Response.ContentType = "text/plain";
                    Console.WriteLine("myMove: " + move);
                    await context.Response.WriteAsync(move);
                }
                else if (context.Request.Method == "POST" && context.Request.Path.Value == "/move")
                {
                    var formData = await context.Request.ReadFormAsync();
                    var lastOpponentMove = formData.FirstOrDefault(x => x.Key == "lastOpponentMove").Value[0];
                    Console.WriteLine("lastOpponentMove: " + lastOpponentMove);
                }

                context.Response.StatusCode = 404;
            });
        }
开发者ID:ducksoupdev,项目名称:dotbot,代码行数:27,代码来源:Program.cs

示例11: Configuration

        public void Configuration(IAppBuilder app)
        {
            app.Run(context =>
            {
                var name = context.Request.Query.Get("name");
                var x = int.Parse(context.Request.Query.Get("x"));
                var y = int.Parse(context.Request.Query.Get("y"));
                var e = Enum.Parse(typeof(MyEnum), context.Request.Query.Get("e"));

                var mc = new MyClass { Name = name, Sum = (x + y) * (int)e };

                var json = JsonConvert.SerializeObject(mc);
                var enc = System.Text.Encoding.UTF8.GetBytes(json);
                context.Response.ContentType = "application/json";

                // sync write or async write
                if (context.Request.Query.Get("sync") == "true")
                {
                    context.Response.Body.Write(enc, 0, enc.Length);
                    return EmptyTask; // Task.FromResult<object>(null)
                }
                else
                {
                    return context.Response.Body.WriteAsync(enc, 0, enc.Length);
                }
            });
        }
开发者ID:KatsuYuzu,项目名称:LightNode,代码行数:27,代码来源:Startup.cs

示例12: WaadAuthenticationWithProviderConfiguration

        public void WaadAuthenticationWithProviderConfiguration(IAppBuilder app)
        {
            app.UseWindowsAzureActiveDirectoryBearerAuthentication(new WindowsAzureActiveDirectoryBearerAuthenticationOptions
                {
                    TokenValidationParameters = new TokenValidationParameters() { ValidAudience = "http://localhost/redirectUri" },
                    Tenant = "4afbc689-805b-48cf-a24c-d4aa3248a248",
                    BackchannelCertificateValidator = new WaadCertificateValidator(),
                    BackchannelHttpHandler = new WaadChannelHttpHandler(),
                });

            app.Run(async context =>
            {
                if (context.Authentication.User == null || !context.Authentication.User.Identity.IsAuthenticated)
                {
                    context.Authentication.Challenge("Bearer");
                    await context.Response.WriteAsync("Unauthorized");
                }
                else
                {
                    if (!context.Get<bool>("OnRequestToken") || !context.Get<bool>("OnValidateIdentity"))
                    {
                        await context.Response.WriteAsync("Provider not invoked");
                    }
                    else
                    {
                        await context.Response.WriteAsync("Bearer");
                    }
                }
            });
        }
开发者ID:Xamarui,项目名称:Katana,代码行数:30,代码来源:WaadAuthentication.cs

示例13: Configuration

        public void Configuration(IAppBuilder appBuilder)
        {
            var config = GetSamlConfiguration();
            #if TEST
            config = TestEnvironmentConfiguration();
            #endif

            appBuilder.UseCookieAuthentication(new Microsoft.Owin.Security.Cookies.CookieAuthenticationOptions
            {
                AuthenticationType = "SAML2",
                AuthenticationMode = Microsoft.Owin.Security.AuthenticationMode.Active
            });
            appBuilder.UseSamlAuthentication(new Owin.Security.Saml.SamlAuthenticationOptions
            {
                Configuration = config,
                RedirectAfterLogin = "/core",
            });
            appBuilder.Run(async c => {
                if (c.Authentication.User != null &&
                    c.Authentication.User.Identity != null &&
                    c.Authentication.User.Identity.IsAuthenticated) {
                    await c.Response.WriteAsync(c.Authentication.User.Identity.Name + "\r\n");
                    await c.Response.WriteAsync(c.Authentication.User.Identity.AuthenticationType + "\r\n");
                    foreach (var claim in c.Authentication.User.Identities.SelectMany(i => i.Claims))
                        await c.Response.WriteAsync(claim.Value + "\r\n");
                    await c.Response.WriteAsync("authenticated");
                } else {
                    // trigger authentication
                    c.Authentication.Challenge(c.Authentication.GetAuthenticationTypes().Select(d => d.AuthenticationType).ToArray());
                }
                return;
            });
        }
开发者ID:jbparker,项目名称:SAML2,代码行数:33,代码来源:Startup.cs

示例14: Configuration

        public void Configuration(IAppBuilder app)
        {
            #if DEBUG
            app.UseErrorPage();
            #endif

            app.UseWelcomePage(new Microsoft.Owin.Diagnostics.WelcomePageOptions()
            {
                Path = new PathString("/welcome")
            });

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

                string output = string.Format(
                    "<p>I'm running on {0} </p><p>From assembly {1}</p>",
                    Environment.OSVersion,
                    System.Reflection.Assembly.GetEntryAssembly().FullName
                    );

                return context.Response.WriteAsync(output);

            });
        }
开发者ID:jabiel,项目名称:monoPi,代码行数:25,代码来源:Startup.cs

示例15: Configuration

		public void Configuration (IAppBuilder app)
		{
			app.Use (typeof(MyMiddleWare));
			app.Run (context => {
				return context.Response.WriteAsync("<h1>HelloWorld Dev</h1>");
			});
		}
开发者ID:haruair-blog,项目名称:HelloWorldOwinHost,代码行数:7,代码来源:Startup.cs


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