public void Configuration(IAppBuilder builder) { builder.UseType<AddBreadCrumbMiddleware>("start-of-the-line"); builder.MapPath("/branch1", builder1 => { builder1.UseType<AddBreadCrumbMiddleware>("took-branch1"); // Nesting paths, e.g. /branch1/branch2 builder1.MapPath("/branch2", builder2 => { builder2.UseType<AddBreadCrumbMiddleware>("took-branch2"); builder2.UseType<DisplayBreadCrumbs>(); }); MapIfIE(builder1); builder1.UseType<DisplayBreadCrumbs>(); }); // Only full segments are matched, so /branch1 does not match /branch100 builder.MapPath("/branch100", builder1 => { builder1.UseType<AddBreadCrumbMiddleware>("took-branch100"); builder1.UseType<DisplayBreadCrumbs>(); }); MapIfIE(builder); builder.UseType<AddBreadCrumbMiddleware>("no-branches-taken"); builder.UseType<DisplayBreadCrumbs>(); }
public void Configuration(IAppBuilder app) { // app.UseFilter(req => req.TraceOutput.WriteLine( // "{0} {1}{2} {3}", // req.Method, req.PathBase, req.Path, req.QueryString)); app.UseErrorPage(); // app.Use(typeof(AutoTuneMiddleware), app.Properties["Microsoft.Owin.Host.HttpListener.OwinHttpListener"]); app.UseSendFileFallback(); app.UseType <CanonicalRequestPatterns>(); app.UseFileServer(opt => opt.WithPhysicalPath("Public")); app.MapPath("/static-compression", map => map .UseStaticCompression() .UseFileServer(opt => { opt.WithDirectoryBrowsing(); opt.WithPhysicalPath("Public"); })); app.MapPath("/danger", map => map .UseStaticCompression() .UseFileServer(opt => { opt.WithDirectoryBrowsing(); opt.StaticFileOptions.ServeUnknownFileTypes = true; })); app.UseDiagnosticsPage("/testpage"); }
public void Configuration(IAppBuilder app) { // app.UseFilter(req => req.TraceOutput.WriteLine( // "{0} {1}{2} {3}", // req.Method, req.PathBase, req.Path, req.QueryString)); app.UseErrorPage(); // app.Use(typeof(AutoTuneMiddleware), app.Properties["Microsoft.Owin.Host.HttpListener.OwinHttpListener"]); app.UseSendFileFallback(); app.UseType<CanonicalRequestPatterns>(); app.UseFileServer(opt => opt.WithPhysicalPath("Public")); app.MapPath("/static-compression", map => map .UseStaticCompression() .UseFileServer(opt => { opt.WithDirectoryBrowsing(); opt.WithPhysicalPath("Public"); })); app.MapPath("/danger", map => map .UseStaticCompression() .UseFileServer(opt => { opt.WithDirectoryBrowsing(); opt.StaticFileOptions.ServeUnknownFileTypes = true; })); app.UseDiagnosticsPage("/testpage"); }
public void Configuration(IAppBuilder builder) { builder.UseType <AddBreadCrumbMiddleware>("start-of-the-line"); builder.MapPath("/branch1", builder1 => { builder1.UseType <AddBreadCrumbMiddleware>("took-branch1"); // Nesting paths, e.g. /branch1/branch2 builder1.MapPath("/branch2", builder2 => { builder2.UseType <AddBreadCrumbMiddleware>("took-branch2"); builder2.UseType <DisplayBreadCrumbs>(); }); MapIfIE(builder1); builder1.UseType <DisplayBreadCrumbs>(); }); // Only full segments are matched, so /branch1 does not match /branch100 builder.MapPath("/branch100", builder1 => { builder1.UseType <AddBreadCrumbMiddleware>("took-branch100"); builder1.UseType <DisplayBreadCrumbs>(); }); MapIfIE(builder); builder.UseType <AddBreadCrumbMiddleware>("no-branches-taken"); builder.UseType <DisplayBreadCrumbs>(); }
public void Configuration(IAppBuilder builder) { // Configure SignalR DI GlobalHost.DependencyResolver.Register(typeof(IDocumentStore), () => _documentStore); // Nancy DI container is configured in its bootstrapper var sampleBootstrapper = new SampleBootstrapper(_documentStore); // Note: it's perfectly viable to have an over-arching single application container // and configure signalr and nancy to use it. builder .MapPath("/fault", faultBuilder => faultBuilder .UseErrorPage(new ErrorPageOptions { ShowExceptionDetails = true }) .UseHandler((request, response) => { throw new Exception("oops!"); })) .MapPath("/files", siteBuilder => siteBuilder .UseBasicAuth((user, pass) => Task.FromResult(pass == "damo")) .UseDenyAnonymous() .UseDirectoryBrowser(@"c:\")) .MapPath("/scripts", scriptsBuilder => scriptsBuilder.UseFileServer("scripts")) .MapPath("/site", siteBuilder => siteBuilder.UseNancy(cfg => cfg.Bootstrapper = sampleBootstrapper)) .MapSignalR() .UseWelcomePage(); }
// Nuget package: Microsoft.Owin.Mapping public void Configuration(IAppBuilder builder) { builder .MapPath("/api", b => b.UseHandler((request, response) => response.StatusCode = 302)) .MapPath("/admin", b => { /* etc */ }) .MapPredicate(env => true, b => { /* etc */ }); }
// Nuget package: Microsoft.Owin.Mapping public void Configuration(IAppBuilder builder) { builder .MapPath("/api", b => b.UseHandler((request, response) => response.StatusCode = 302)) .MapPath("/admin", b => { /* etc */}) .MapPredicate(env => true, b => { /* etc */}); }
public void Configuration(IAppBuilder builder) { // Configure SignalR DI GlobalHost.DependencyResolver.Register(typeof (IDocumentStore), () => _documentStore); // Nancy DI container is configured in its bootstrapper var sampleBootstrapper = new SampleBootstrapper(_documentStore); // Note: it's perfectly viable to have an over-arching single application container // and configure signalr and nancy to use it. builder .MapPath("/fault", faultBuilder => faultBuilder .UseShowExceptions() .UseHandler((request, response) => { throw new Exception("oops!"); })) .MapPath("/files", siteBuilder => siteBuilder .UseBasicAuth((user, pass) => Task.FromResult(pass == "damo")) .UseDenyAnonymous() .UseDirectoryBrowser(@"c:\")) .MapPath("/scripts", scriptsBuilder => scriptsBuilder.UseFileServer("scripts")) .MapPath("/site", siteBuilder => siteBuilder.UseNancy(sampleBootstrapper)) .MapHubs() .UseTestPage(); }
private static void SetupMiddleware(IApplicationSettings settings, IAppBuilder app) { if (settings.ProxyImages) { app.MapPath("/proxy", subApp => subApp.Use(typeof(ImageProxyHandler), settings)); } app.UseStaticFiles(); }
public void Configuration(IAppBuilder app) { app.MapPath("/site", siteBuilder => siteBuilder.UseNancy()); }
private static void SetupNancy(IKernel kernel, IAppBuilder app) { var bootstrapper = new JabbRNinjectNancyBootstrapper(kernel); app.MapPath("/auth", subApp => subApp.UseNancy(bootstrapper)); }
public void Configuration(IAppBuilder builder) { builder.MapPath("/admin", adminBuilder => adminBuilder .DenyNonLocalRequests() .UseHandler((request, response) => response.Write("You're in."))); }
private static void SetupMiddleware(IAppBuilder app) { app.MapPath("/proxy", subApp => subApp.Use(typeof(ImageProxyHandler))); app.UseStaticFiles(); }
public void Configuration(IAppBuilder builder) { var rootDirectory = Environment.CurrentDirectory; var loginDirectory = Path.Combine(rootDirectory, "login"); var fs = new PhysicalFileSystem(rootDirectory); var loginFs = new PhysicalFileSystem(loginDirectory); var dfo = new DefaultFilesOptions(); dfo.DefaultFileNames.Add("index.html"); dfo.FileSystem = fs; var sfo = new StaticFileOptions { FileSystem = fs }; var loginSfo = new StaticFileOptions { FileSystem = loginFs }; builder.SetDataProtectionProvider(new DpapiDataProtectionProvider()); var formsAuthenticationProvider = new FormsAuthenticationProvider(); formsAuthenticationProvider.OnValidateLogin = context => { Console.WriteLine("Validating Login"); Console.WriteLine("================"); Console.WriteLine(" Context.AuthType: " + context.AuthenticationType); Console.WriteLine(" Context.Identity: " + (context.Identity != null ? context.Identity.Name : "Not set")); Console.WriteLine(" Context.Environment:"); var response = new OwinResponse(context.Environment); if (LoginContext.GetIsLoginRequest(context.Environment)) { // Need to retrieve username and password from environment b/c it doesn't // come through in the context (even though the context constructor accepts them) var username = context.Environment["formsauthn.username"].ToString(); var password = context.Environment["formsauthn.password"].ToString(); var remember = bool.Parse(context.Environment["formsauthn.remember"].ToString()); Console.WriteLine(" Request.Username: "******" Request.Password: "******" Request.Remember: " + remember); if (username == password) { var identity = new ClaimsIdentity( new GenericIdentity(username, context.AuthenticationType), new[] { new Claim(ClaimTypes.IsPersistent, remember.ToString()) } ); // I assumed that this would take care of populating the cookie for me... but not so much. context.Signin(identity); var msg = "Access granted."; Console.WriteLine(msg); var msgBytes = Encoding.UTF8.GetBytes(msg); return(response.Body.WriteAsync(msgBytes, 0, msgBytes.Length)); } else { var msg = "Access denied. Try with username=password"; Console.WriteLine(msg); var msgBytes = Encoding.UTF8.GetBytes(msg); return(response.Body.WriteAsync(msgBytes, 0, msgBytes.Length)); } } else { foreach (var item in context.Environment) { Console.WriteLine(" {0}={1}", item.Key, item.Value != null ? (item.Value is string?(string)item.Value: item.Value.GetType().FullName) : "Not set" ); } } return(response.Body.WriteAsync(new byte[] { }, 0, 0)); }; builder.UseFormsAuthentication( new FormsAuthenticationOptions { CookieHttpOnly = true, CookieName = "AuthCookie", CookiePath = "/", CookieSecure = false, LoginPath = "/login/", ExpireTimeSpan = TimeSpan.FromHours(1), ReturnUrlParameter = "returnUrl", SlidingExpiration = true, Provider = formsAuthenticationProvider } ); builder.UseApplicationSignInCookie(); builder.UseDefaultFiles(dfo); builder.UseErrorPage(); builder.MapPath("/login", loginBuilder => loginBuilder.UseProcessLoginPostback(formsAuthenticationProvider).UseStaticFiles(loginSfo)); builder.UseDenyAnonymous().UseStaticFiles(sfo); }
public void Configuration(IAppBuilder builder) { var rootDirectory = Environment.CurrentDirectory; var loginDirectory = Path.Combine(rootDirectory, "login"); var fs = new PhysicalFileSystem(rootDirectory); var loginFs = new PhysicalFileSystem(loginDirectory); var dfo = new DefaultFilesOptions(); dfo.DefaultFileNames.Add("index.html"); dfo.FileSystem = fs; var sfo = new StaticFileOptions { FileSystem = fs }; var loginSfo = new StaticFileOptions { FileSystem = loginFs }; builder.SetDataProtectionProvider(new DpapiDataProtectionProvider()); var formsAuthenticationProvider = new FormsAuthenticationProvider(); formsAuthenticationProvider.OnValidateLogin = context => { Console.WriteLine("Validating Login"); Console.WriteLine("================"); Console.WriteLine(" Context.AuthType: " + context.AuthenticationType); Console.WriteLine(" Context.Identity: " + (context.Identity != null ? context.Identity.Name : "Not set")); Console.WriteLine(" Context.Environment:"); var response = new OwinResponse(context.Environment); if (LoginContext.GetIsLoginRequest(context.Environment)) { // Need to retrieve username and password from environment b/c it doesn't // come through in the context (even though the context constructor accepts them) var username = context.Environment["formsauthn.username"].ToString(); var password = context.Environment["formsauthn.password"].ToString(); var remember = bool.Parse(context.Environment["formsauthn.remember"].ToString()); Console.WriteLine(" Request.Username: "******" Request.Password: "******" Request.Remember: " + remember); if (username == password) { var identity = new ClaimsIdentity( new GenericIdentity(username, context.AuthenticationType), new[] { new Claim(ClaimTypes.IsPersistent, remember.ToString()) } ); // I assumed that this would take care of populating the cookie for me... but not so much. context.Signin(identity); var msg = "Access granted."; Console.WriteLine(msg); var msgBytes = Encoding.UTF8.GetBytes(msg); return response.Body.WriteAsync(msgBytes, 0, msgBytes.Length); } else { var msg = "Access denied. Try with username=password"; Console.WriteLine(msg); var msgBytes = Encoding.UTF8.GetBytes(msg); return response.Body.WriteAsync(msgBytes, 0, msgBytes.Length); } } else { foreach (var item in context.Environment) { Console.WriteLine(" {0}={1}", item.Key, item.Value != null ? (item.Value is string ? (string) item.Value : item.Value.GetType().FullName) : "Not set" ); } } return response.Body.WriteAsync(new byte[] { }, 0, 0); }; builder.UseFormsAuthentication( new FormsAuthenticationOptions { CookieHttpOnly = true, CookieName = "AuthCookie", CookiePath = "/", CookieSecure = false, LoginPath = "/login/", ExpireTimeSpan = TimeSpan.FromHours(1), ReturnUrlParameter = "returnUrl", SlidingExpiration = true, Provider = formsAuthenticationProvider } ); builder.UseApplicationSignInCookie(); builder.UseDefaultFiles(dfo); builder.UseErrorPage(); builder.MapPath("/login", loginBuilder => loginBuilder.UseProcessLoginPostback(formsAuthenticationProvider).UseStaticFiles(loginSfo)); builder.UseDenyAnonymous().UseStaticFiles(sfo); }