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


C# IAppBuilder.UseHandlerAsync方法代码示例

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


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

示例1: Configuration

 public void Configuration(IAppBuilder app)
 {
     app.UseHandlerAsync((req, res) =>
     {
         res.ContentType = "text/plain";
         return res.WriteAsync("Hello World!");
     });
 }
开发者ID:ledgarl,项目名称:Samples,代码行数:8,代码来源:Startup.cs

示例2: Configuration

        public void Configuration(IAppBuilder app)
        {
            app.UseFileServer(true);
            app.UseWelcomePage("/welkom");

            app.UseHandlerAsync((req, res, next) =>
            {
                if (req.Path == "/owin")
                {
                    res.StatusCode = 302;
                    res.AddHeader("Location", "http://owin.org/");
                    return Task.FromResult(0);
                }
                return next();
            });

            app.UseHandlerAsync(RequestDump);
        }
开发者ID:cbenitezatnetmark,项目名称:TechDaysMVC5,代码行数:18,代码来源:Startup.cs

示例3: Configuration

 public void Configuration(IAppBuilder app)
 {
     ConfigureApi(app);
     app.UseNancy(new NancyOptions { Bootstrapper = new NancyBootstrapper() });
     app.UseHandlerAsync((req, res) =>
     {
         res.ContentType = "text/plain";
         return res.WriteAsync("OWIN Web Application Final step");
     });
 }
开发者ID:swimtver,项目名称:Owin,代码行数:10,代码来源:Startup.cs

示例4: Configuration

        public void Configuration(IAppBuilder app)
        {
            app.Use<LoggerMiddleware>();

            var config = new HttpConfiguration();
            config.Routes.MapHttpRoute("default", "{controller}");
            app.UseWebApi(config);

            app.UseHandlerAsync((req, res) =>
            {
                res.ContentType = "text/plain";
                return res.WriteAsync("Hello World!");
            });
        }
开发者ID:davidalmas,项目名称:Samples,代码行数:14,代码来源:Startup.cs

示例5: Configuration

        public void Configuration(IAppBuilder app)
        {
            //app.UseOpenIdConnectAuthentication(
            //    new OpenIdConnectAuthenticationOptions
            //    {
            //        ClientId = "oidccode",
            //        ClientSecret = "secret",
            //        Scope = "openid profile",

            //        ReturnPath = "/oidccallback",
            //        RedirectUri = new Uri("https://localhost:44310/oidccallback"),
            //        AuthorizeEndpoint = new Uri("https://idsrv.local/issue/oidc/authorize"),
            //        SigninAsAuthenticationType = "Federation"
            //    });


            // authentication
            //app.Use(typeof(AuthenticationMiddleware));
            //app.Use(typeof(SetPrincipalMiddleware));

            // web api
            //var httpConfig = new HttpConfiguration();
            //httpConfig.Routes.MapHttpRoute(
            //    "default",
            //    "api/{controller}");

            //app.UseWebApi(httpConfig);

            // plain http handler
            app.UseHandlerAsync((req, res) =>
            {
                res.ContentType = "text/plain";

                if (Thread.CurrentPrincipal.Identity.IsAuthenticated)
                {
                    return res.WriteAsync("Hello " + Thread.CurrentPrincipal.Identity.Name);
                }
                else
                {
                    //res.StatusCode = 401;
                    return res.WriteAsync("Hello stranger!");
                }
            });
        }
开发者ID:cotepatrice,项目名称:Thinktecture.IdentityServer.v2,代码行数:44,代码来源:Startup.cs

示例6: Configuration

        public void Configuration(IAppBuilder app)
        {
            var webserverOptions = new WebserverOptions
            {
                BasePath = Environment.CurrentDirectory
            };

            app.Use(typeof(TraceMiddleware));
            app.UseHandlerAsync((request, response, next) =>
            {
                response.AddHeader("Server", "dotnetpro Webserver");
                return next();
            });

            app.Use(typeof(GitReceivePackMiddleware), webserverOptions);
            app.Use(typeof(IsPrivateFolderMiddleware), webserverOptions);
            app.Use(typeof(ResourceExistMiddleware), webserverOptions);
            app.Use(typeof(DefaultMiddleware), webserverOptions);
        }
开发者ID:JuergenGutsch,项目名称:dotnetpro-node-vs-net,代码行数:19,代码来源:Startup.cs

示例7: Configuration

        public void Configuration(IAppBuilder app)
        {
            var logger = app.CreateLogger("Katana.Sandbox.WebServer");

            logger.WriteInformation("Application Started");

            app.UseHandlerAsync(async (req, res, next) =>
            {
                req.TraceOutput.WriteLine("{0} {1}{2}", req.Method, req.PathBase, req.Path);
                await next();
                req.TraceOutput.WriteLine("{0} {1}{2}", res.StatusCode, req.PathBase, req.Path);
            });

            app.UseFormsAuthentication(new FormsAuthenticationOptions
            {
                AuthenticationType = "Application",
                AuthenticationMode = AuthenticationMode.Passive,
                LoginPath = "/Login",
                LogoutPath = "/Logout",
            });

            app.UseExternalSignInCookie();

            app.UseFacebookAuthentication(new FacebookAuthenticationOptions
            {
                SignInAsAuthenticationType = "External",
                AppId = "615948391767418",
                AppSecret = "c9b1fa6b68db835890ce469e0d98157f",
                // Scope = "email user_birthday user_website"
            });

            app.UseGoogleAuthentication();

            app.UseTwitterAuthentication("6XaCTaLbMqfj6ww3zvZ5g", "Il2eFzGIrYhz6BWjYhVXBPQSfZuS4xoHpSSyD9PI");

            app.UseMicrosoftAccountAuthentication("000000004C0EA787", "QZde5m5HHZPxdieV0lOy7bBVTbVqR9Ju");

            app.UseOAuthBearerAuthentication(new OAuthBearerAuthenticationOptions
            {
            });

            // CORS support
            app.UseHandlerAsync(async (req, res, next) =>
            {
                // for auth2 token requests, and web api requests
                if (req.Path == "/Token" || req.Path.StartsWith("/api/"))
                {
                    // if there is an origin header
                    var origin = req.GetHeader("Origin");
                    if (!string.IsNullOrEmpty(origin))
                    {
                        // allow the cross-site request
                        res.AddHeader("Access-Control-Allow-Origin", origin);
                    }

                    // if this is pre-flight request
                    if (req.Method == "OPTIONS")
                    {
                        // respond immediately with allowed request methods and headers
                        res.StatusCode = 200;
                        res.AddHeaderJoined("Access-Control-Allow-Methods", "GET", "POST");
                        res.AddHeaderJoined("Access-Control-Allow-Headers", "authorization");
                        // no further processing
                        return;
                    }
                }
                // continue executing pipeline
                await next();
            });

            app.UseOAuthAuthorizationServer(new OAuthAuthorizationServerOptions
            {
                AuthorizeEndpointPath = "/Authorize",
                TokenEndpointPath = "/Token",
                Provider = new OAuthAuthorizationServerProvider
                {
                    OnValidateClientCredentials = OnValidateClientCredentials,
                    OnValidateResourceOwnerCredentials = OnValidateResourceOwnerCredentials,
                },
            });

            var config = new HttpConfiguration();
            config.Routes.MapHttpRoute("Default", "api/{controller}");
            app.UseWebApi(config);
        }
开发者ID:tkggand,项目名称:katana,代码行数:85,代码来源:Startup.cs

示例8: Configuration

 public void Configuration(IAppBuilder builder)
 {
     builder.UseHandlerAsync((request, response) => response.WriteAsync("Sup"));
 }
开发者ID:Eugene1982,项目名称:NancySignalrOwin,代码行数:4,代码来源:_02_Owin_Extensions.cs

示例9: Configuration

 // Invoked once at startup to configure your application.
 public void Configuration(IAppBuilder builder)
 {
     builder.UseHandlerAsync(Invoke);
 }
开发者ID:srihari-sridharan,项目名称:Programming-Playground,代码行数:5,代码来源:Startup.cs


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