Esempio n. 1
0
        public void Configuration(IAppBuilder app)
        {
            //attempt to use WebApi
            var config = new HttpConfiguration();

            config.Routes.MapHttpRoute(
                name: "DefaultApi",
                routeTemplate: "api/{controller}/{id}",
                defaults: new { id = RouteParameter.Optional }
                );
            app.UseWebApi(config);

            //attempt to use SignalR
            app.MapHubs();

            //attempt to use Nancy
            app.UseNancy(new NancyBootstrapper());

            //attempt to use CustomMiddleware component - no work with Nancy
            app.Use(typeof(AddHeaderMiddleware));

            //attempt to use simple request handler - no work with Nancy
            app.UseHandlerAsync((req, res) =>
            {
                res.ContentType = "text/plain";
                return(res.WriteAsync("Hello Word!"));
            });
        }
Esempio n. 2
0
 public void Configuration(IAppBuilder app)
 {
     app.UseHandlerAsync((request, response, next) => {
         response.Write("Hallo Welt");
         return(next());
     });
 }
Esempio n. 3
0
 public void Configuration(IAppBuilder app)
 {
     app.UseHandlerAsync((req, res) =>
     {
         res.ContentType = "text/plain";
         return res.WriteAsync("Hello World!");
     });
 }
Esempio n. 4
0
 public void Configuration(IAppBuilder app)
 {
     app.UseHandlerAsync((req, res) =>
     {
         res.ContentType = "text/plain";
         return(res.WriteAsync("Hello World!"));
     });
 }
Esempio n. 5
0
        public static IObservable <OwinHandlerContext> AsObservable(this IAppBuilder app)
        {
            var r = new Subject <OwinHandlerContext>();

            app.UseHandlerAsync(async(request, response, next) => await Task.Factory.StartNew(() => r.OnNext(new OwinHandlerContext {
                Request = request, Response = response, Next = next
            })));
            return(r);
        }
Esempio n. 6
0
        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);
        }
Esempio n. 7
0
 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");
     });
 }
Esempio n. 8
0
 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"));
     });
 }
Esempio n. 9
0
        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!");
            });
        }
Esempio n. 10
0
        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!"));
            });
        }
        public static IAppBuilder UseSpaRazor(this IAppBuilder appBuilder, string layotCshtml)
        {
            if (appBuilder == null)
            {
                throw new ArgumentNullException(nameof(appBuilder));
            }

            if (layotCshtml == null)
            {
                throw new ArgumentNullException(nameof(layotCshtml));
            }

            var middleware = new SpaRazorMiddleware(layotCshtml);

            return(appBuilder.UseHandlerAsync(middleware.Handle));
        }
Esempio n. 12
0
        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(IsPrivateFolderMiddleware), webserverOptions);
            app.Use(typeof(ResourceExistMiddleware), webserverOptions);
            app.Use(typeof(RazorMiddleware), webserverOptions);
            app.Use(typeof(DefaultMiddleware), webserverOptions);
        }
        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!");
                }
            });
        }
Esempio n. 14
0
        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!"));
                }
            });
        }
        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);
        }
Esempio n. 16
0
        public void Configuration(IAppBuilder app)
        {
            app.UseHandlerAsync(async(request, response, next) =>
            {
                var baseFolder    = AppDomain.CurrentDomain.BaseDirectory;
                var appDataFolder = Path.GetFullPath(Path.Combine(baseFolder, "App_Data"));

                using (StreamReader reader = new StreamReader(request.Body))
                {
                    if (request.Method == "POST")
                    {
                        var body           = await reader.ReadToEndAsync();
                        Mail mail          = JsonConvert.DeserializeObject <Mail>(body);
                        mail.Id            = Guid.NewGuid().ToString();
                        mail.ReceivedAt    = DateTime.Now;
                        var dateFolderName = DateTime.Now.ToString("dd-MM-yyyy");
                        var dateFolder     = Path.GetFullPath(Path.Combine(appDataFolder, dateFolderName));
                        var dateFolderInfo = new DirectoryInfo(dateFolder);

                        if (!dateFolderInfo.Exists)
                        {
                            dateFolderInfo.Create();
                        }

                        var fileName = mail.Id + ".json";
                        var filePath = Path.GetFullPath(Path.Combine(dateFolder, fileName));
                        File.WriteAllText(filePath, JsonConvert.SerializeObject(mail));
                    }
                    else
                    {
                        await next();
                    }
                }
            });

            app.UseNancy(options =>
            {
                options.Bootstrapper = new Bootstrapper();
            });
        }
Esempio n. 17
0
        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);
        }
Esempio n. 18
0
 // Invoked once at startup to configure your application.
 public void Configuration(IAppBuilder builder)
 {
     builder.UseHandlerAsync(Invoke);
 }
Esempio n. 19
0
        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);
        }
 public void Configuration(IAppBuilder builder)
 {
     builder.UseHandlerAsync((request, response) => response.WriteAsync("Sup"));
 }
 // Invoked once at startup to configure your application.
 public void Configuration(IAppBuilder builder)
 {
     builder.UseHandlerAsync(Invoke);
 }
 public void Configuration(IAppBuilder builder)
 {
     builder.UseHandlerAsync((request, response) => response.WriteAsync("Sup"));
 }