/// <summary> /// UseErrorPage method /// </summary> /// <param name="app"></param> private void UseErrorPage(IAppBuilder app) { Logger.Trace("UseErrorPage Begin"); app.UseErrorPage(new ErrorPageOptions() { ShowCookies = true, ShowEnvironment = true, ShowExceptionDetails = true, ShowHeaders = true, ShowQuery = true, ShowSourceCode = true }); if (new Feature_ErrorPage().FeatureEnabled) { Logger.Info("FEATURE :: ERROR PAGE --> ENABLED"); app.UseErrorPage(); } else { Logger.Warn("FEATURE :: ERROR PAGE --> DISABLED"); } Logger.Trace("UseErrorPage Complete"); }
private void Startup(IAppBuilder appBuilder) { #if DEBUG appBuilder.Properties["host.AppMode"] = "development"; // TODO why development ??? appBuilder.UseErrorPage(new Microsoft.Owin.Diagnostics.ErrorPageOptions { ShowExceptionDetails = true }); #else appBuilder.UseErrorPage(); #endif ConfigureWebApi(appBuilder); if (UseSignalR) { ConfigureSignalR(appBuilder); } if (UseFileServer) { ConfigureFileServer(appBuilder); } else { appBuilder.UseWelcomePage("/owin/"); } }
public void Configuration(IAppBuilder app) { var configuration = new JabbrConfiguration(); if (configuration.MigrateDatabase) { // Perform the required migrations DoMigrations(); } var kernel = SetupNinject(configuration); app.Use(typeof(DetectSchemeHandler)); if (configuration.RequireHttps) { app.Use(typeof(RequireHttpsHandler)); } app.UseErrorPage(); SetupAuth(app, kernel); SetupSignalR(kernel, app); SetupWebApi(kernel, app); SetupMiddleware(kernel, app); SetupNancy(kernel, app); SetupErrorHandling(); }
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); }); }
public void Configuration(IAppBuilder app) { #if DEBUG app.UseErrorPage(new ErrorPageOptions { //Shows the OWIN environment dictionary keys and values. //This detail is enabled by default if you are running your app from VS unless disabled in code. ShowEnvironment = true, //Hides cookie details ShowCookies = true, //Shows the lines of code throwing this exception. //This detail is enabled by default if you are running your app from VS unless disabled in code. ShowSourceCode = true }); //for test ErrorPage //app.Run(async context => //{ // throw new Exception("UseErrorPage() demo"); // await context.Response.WriteAsync("Error page demo"); //}); app.UseWelcomePage("/"); // for test purpose only #endif ConfigureOAuth(app); var config = new HttpConfiguration(); WebApiConfig.Register(config); app.UseCors(Microsoft.Owin.Cors.CorsOptions.AllowAll); app.UseWebApi(config); }
public void Configuration(IAppBuilder app) { // So that squishit works Directory.SetCurrentDirectory(AppDomain.CurrentDomain.SetupInformation.ApplicationBase); var configuration = new JabbrConfiguration(); if (configuration.MigrateDatabase) { // Perform the required migrations DoMigrations(); } var kernel = SetupNinject(configuration); app.Use(typeof(DetectSchemeHandler)); if (configuration.RequireHttps) { app.Use(typeof(RequireHttpsHandler)); } app.UseErrorPage(); SetupAuth(app, kernel); SetupSignalR(configuration, kernel, app); SetupWebApi(kernel, app); SetupMiddleware(kernel, app); SetupFileUpload(kernel, app); SetupNancy(kernel, app); SetupErrorHandling(); }
public void Configuration(IAppBuilder app) { /* // Note: Enable only for debugging. This slows down the perf tests. app.Use((context, next) => { var req = context.Request; context.TraceOutput.WriteLine("{0} {1}{2} {3}", req.Method, req.PathBase, req.Path, req.QueryString); return next(); });*/ app.UseErrorPage(new ErrorPageOptions { SourceCodeLineCount = 20 }); // app.Use(typeof(AutoTuneMiddleware), app.Properties["Microsoft.Owin.Host.HttpListener.OwinHttpListener"]); app.UseSendFileFallback(); app.Use<CanonicalRequestPatterns>(); app.UseStaticFiles(new StaticFileOptions() { RequestPath = new PathString("/static"), FileSystem = new PhysicalFileSystem("public") }); app.UseDirectoryBrowser(new DirectoryBrowserOptions() { RequestPath = new PathString("/static"), FileSystem = new PhysicalFileSystem("public") }); app.UseStageMarker(PipelineStage.MapHandler); FileServerOptions options = new FileServerOptions(); options.EnableDirectoryBrowsing = true; options.StaticFileOptions.ServeUnknownFileTypes = true; app.UseWelcomePage("/Welcome"); }
public void Configuration(IAppBuilder app) { // So that squishit works Directory.SetCurrentDirectory(AppDomain.CurrentDomain.SetupInformation.ApplicationBase); var configuration = new ChatConfiguration(); var kernel = SetupNinject(configuration); if (configuration.MigrateDatabase && !DataSettingsHelper.DatabaseIsInstalled()) { // Perform the required migrations var migrations = new StartupDoMigrations(configuration, kernel); migrations.DoMigrations(); } app.Use(typeof(DetectSchemeHandler)); if (configuration.RequireHttps) { app.Use(typeof(RequireHttpsHandler)); } app.UseErrorPage(); SetupAuth(app, kernel); SetupSignalR(configuration, kernel, app); SetupWebApi(kernel, app); SetupMiddleware(kernel, app); SetupNancy(kernel, app); SetupErrorHandling(); }
public void Configuration(IAppBuilder app) { // Show an error page app.UseErrorPage(); // Logging component app.Use <LoggingComponent>(); // Configure web api routing var config = new HttpConfiguration(); config.MapHttpAttributeRoutes(); config.Routes.MapHttpRoute( name: "DefaultApi", routeTemplate: "api/{controller}/{id}", defaults: new { id = RouteParameter.Optional } ); // Use web api middleware app.UseWebApi(config); // Throw an exception app.Use(async(context, next) => { if (context.Request.Path.ToString() == "/fail") { throw new Exception("Doh!"); } await next(); }); // Welcome page app.UseWelcomePage("/"); }
public void Configuration(IAppBuilder app) { app.UseErrorPage(); app.Map("/raw-connection", map => { // Turns cors support on allowing everything // In real applications, the origins should be locked down map.UseCors(CorsOptions.AllowAll) .RunSignalR <RawConnection>(); }); app.Map("/signalr", map => { var config = new HubConfiguration { // You can enable JSONP by uncommenting this line // JSONP requests are insecure but some older browsers (and some // versions of IE) require JSONP to work cross domain // EnableJSONP = true }; // Turns cors support on allowing everything // In real applications, the origins should be locked down map.UseCors(CorsOptions.AllowAll) .RunSignalR(config); }); // Turn tracing on programmatically GlobalHost.TraceManager.Switch.Level = SourceLevels.All; }
public void Configuration(IAppBuilder app) { #if DEBUG app.UseErrorPage(); #endif app.Use( async (context, next) => { // Log all exceptions and incoming requests Console.WriteLine("{0} {1} {2}", context.Request.Method, context.Request.Path, context.Request.QueryString); try { await next(); } catch (Exception exception) { Console.WriteLine(exception.ToString()); throw; } }); var contentFileSystem = new PhysicalFileSystem("Content"); app.UseBabel(new BabelFileOptions() { StaticFileOptions = new StaticFileOptions() { FileSystem = contentFileSystem }}); app.UseFileServer(new FileServerOptions() { FileSystem = contentFileSystem }); app.Use<CommentsMiddleware>(); }
internal void ModuleAndHandlerSyncException(IAppBuilder app) { app.UseErrorPage(); app.Use(async(context, next) => { // Expect async exception from the handler. try { await next(); Assert.True(false, "Handler exception expected"); } catch (NotFiniteNumberException) { } }); RouteTable.Routes.MapOwinPath("/", app2 => { app2.Run(context2 => { // Sync exception should become async before module sees it. throw new NotFiniteNumberException("Handler exception"); }); }); }
public void Configuration(IAppBuilder app) { //Startup.ConfigureAuth(); app.UseErrorPage(); // See Microsoft.Owin.Diagnostics app.UseWelcomePage("/Welcome"); // See Microsoft.Owin.Diagnostics //app.Run(async context => //{ // await context.Response.WriteAsync("Hello world using OWIN TestServer"); //}); //Get your HttpConfiguration. In OWIN, you'll create one //rather than using GlobalConfiguration. var config = new HttpConfiguration(); WebApiConfig.Register(config); //// OWIN WEB API SETUP: //// Register the Autofac middleware FIRST, then the Autofac Web API middleware, //// and finally the standard Web API middleware. app.UseWebApi(config); HttpContext.Current = new HttpContext(new HttpRequest("", "http://tempuri.org", ""), new HttpResponse(new StringWriter()) ); }
public void Configuration(IAppBuilder app) { var relativePath = string.Format(@"..{0}..{0}", Path.DirectorySeparatorChar); var contentPath = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), relativePath); app.UseErrorPage(); app.Use(async (ctx, next) => { await next(); Console.WriteLine($"{DateTime.Now.ToLongTimeString()}: {ctx.Request.Method} {ctx.Request.Uri.AbsolutePath}: {ctx.Response.StatusCode} {ctx.Response.ReasonPhrase}"); }); app.UseFileServer(new FileServerOptions() { RequestPath = PathString.Empty, FileSystem = new PhysicalFileSystem(Path.Combine(contentPath, @"wwwroot")), EnableDirectoryBrowsing = false }); var config = new HttpConfiguration(); config.Routes.MapHttpRoute( name: "DefaultApi", routeTemplate: "api/{controller}/{id}", defaults: new { id = RouteParameter.Optional } ); app.UseWebApi(config); }
public void Configuration(IAppBuilder app) { #if DEBUG app.UseErrorPage(); #endif // Remap '/' to '.\defaults\'. // Turns on static files and default files. app.UseFileServer(new FileServerOptions() { RequestPath = PathString.Empty, FileSystem = new PhysicalFileSystem(@".\defaults"), }); // Only serve files requested by name. app.UseStaticFiles("/files"); // Turns on static files, directory browsing, and default files. app.UseFileServer(new FileServerOptions() { RequestPath = new PathString("/public"), EnableDirectoryBrowsing = true, }); // Browse the root of your application (but do not serve the files). // NOTE: Avoid serving static files from the root of your application or bin folder, // it allows people to download your application binaries, config files, etc.. app.UseDirectoryBrowser(new DirectoryBrowserOptions() { RequestPath = new PathString("/src"), FileSystem = new PhysicalFileSystem(@""), }); // Anything not handled will land at the welcome page. app.UseWelcomePage(); }
public void KnownStagesSpecified(IAppBuilder app) { app.UseErrorPage(); app.Use<BreadCrumbMiddleware>("a", "Authenticate"); AddStageMarker(app, "Authenticate"); app.Use<BreadCrumbMiddleware>("b", "PostAuthenticate"); AddStageMarker(app, "PostAuthenticate"); app.Use<BreadCrumbMiddleware>("c", "Authorize"); AddStageMarker(app, "Authorize"); app.Use<BreadCrumbMiddleware>("d", "PostAuthorize"); AddStageMarker(app, "PostAuthorize"); app.Use<BreadCrumbMiddleware>("e", "ResolveCache"); AddStageMarker(app, "ResolveCache"); app.Use<BreadCrumbMiddleware>("f", "PostResolveCache"); AddStageMarker(app, "PostResolveCache"); app.Use<BreadCrumbMiddleware>("g", "MapHandler"); AddStageMarker(app, "MapHandler"); app.Use<BreadCrumbMiddleware>("h", "PostMapHandler"); AddStageMarker(app, "PostMapHandler"); app.Use<BreadCrumbMiddleware>("i", "AcquireState"); AddStageMarker(app, "AcquireState"); app.Use<BreadCrumbMiddleware>("j", "PostAcquireState"); AddStageMarker(app, "PostAcquireState"); app.Use<BreadCrumbMiddleware>("k", "PreHandlerExecute"); AddStageMarker(app, "PreHandlerExecute"); app.Run(context => { var fullBreadCrumb = context.Get<string>("test.BreadCrumb"); Assert.Equal("abcdefghijk", fullBreadCrumb); return Task.FromResult(0); }); }
public void Configuration(IAppBuilder app) { // This example shows how to use the Ninject IoC container to construct the // Owin pipeline buider. You can use any other IoC container supported by // the Ioc.Modules package with just one line of code change. You can also // choose not to use IoC, or configure any other IoC container you like. var packageLocator = new PackageLocator().ProbeAllLoadedAssemblies(); var ninject = new StandardKernel(new Module(packageLocator)); var builder = ninject.Get <IBuilder>(); // This next part defines the concrete implementation of the various // OWIN middleware components you want to use in your application. The // order that these will be chained into the OWIN pipeline will be // determined from the dependencies defined within the components. // This is a simplified example, in a real application you should provide a // configuration mechanism. This example will run with all default // configuration values. builder.Register(ninject.Get <NotFoundError>()); builder.Register(ninject.Get <PrintRequest>()); builder.Register(ninject.Get <ReportExceptions>()); builder.Register(ninject.Get <FormsIdentification>()); builder.Register(ninject.Get <TemplatePageRendering>()); builder.Register(ninject.Get <AllowEverythingAuthorization>()); builder.Register(ninject.Get <InProcessSession>()); // The next few lines build the Owin pipeline. Note that the // Owin Framework builder adds to the pipeline but other middleware // can also be added to the pipeline before or after it. app.UseErrorPage(); app.UseBuilder(builder); app.UseWelcomePage("/"); }
protected virtual void Start(IAppBuilder app, IContainer container) { var config = CreateHttpConfiguration(); ConfigureWebApi(config); if (Settings.ShowExceptionDetails) { app.UseErrorPage(new ErrorPageOptions { ShowExceptionDetails = true, ShowSourceCode = true }); } app.UseAutofacMiddleware(container); app.UseAutofacWebApi(config); app.UseWebApi(config); RegisterSignalR(container, app); app.UseStageMarker(PipelineStage.MapHandler); RegisterServices(container, app, config); RegisterShutdown(app, container); StartIndexingIfConfigured(container); }
public void OutOfOrderMarkers(IAppBuilder app) { app.UseErrorPage(); app.Use <BreadCrumbMiddleware>("a", "Authenticate"); AddStageMarker(app, "PostResolveCache"); // 5 app.Use <BreadCrumbMiddleware>("b", "Authenticate"); AddStageMarker(app, "PostAuthenticate"); // 1 app.Use <BreadCrumbMiddleware>("c", "Authenticate"); AddStageMarker(app, "Authenticate"); // 0 app.Use <BreadCrumbMiddleware>("d", "Authorize"); AddStageMarker(app, "Authorize"); // 2 app.Use <BreadCrumbMiddleware>("e", "PostAuthorize"); AddStageMarker(app, "ResolveCache"); // 4 app.Use <BreadCrumbMiddleware>("f", "PostAuthorize"); AddStageMarker(app, "PostAuthorize"); // 3 app.Use <BreadCrumbMiddleware>("g", "MapHandler"); AddStageMarker(app, "MapHandler"); // 6 app.Use <BreadCrumbMiddleware>("h", "PostMapHandler"); AddStageMarker(app, "PostAcquireState"); // 9 app.Use <BreadCrumbMiddleware>("i", "PostMapHandler"); AddStageMarker(app, "AcquireState"); // 8 app.Use <BreadCrumbMiddleware>("j", "PostMapHandler"); AddStageMarker(app, "PostMapHandler"); // 7 app.Use <BreadCrumbMiddleware>("k", "PreHandlerExecute"); AddStageMarker(app, "PreHandlerExecute"); // 10 app.Run(context => { var fullBreadCrumb = context.Get <string>("test.BreadCrumb"); Assert.Equal("abcdefghijk", fullBreadCrumb); return(TaskHelpers.Completed()); }); }
public void SetSpecialHeadersApp(IAppBuilder app) { app.UseErrorPage(new ErrorPageOptions() { ShowExceptionDetails = true }); app.Run(context => { IHeaderDictionary responseHeaders = context.Response.Headers; foreach (var header in _specialHeaders) { responseHeaders[header.Key] = header.Value; Assert.True(responseHeaders.ContainsKey(header.Key), header.Key); Assert.Equal(header.Value, responseHeaders[header.Key]); } Assert.Equal(_specialHeaders.Length, responseHeaders.Count); Assert.Equal(_specialHeaders.Length, responseHeaders.Count()); // All show up in enumeration? foreach (var specialPair in _specialHeaders) { Assert.True(responseHeaders.Select(pair => pair.Key) .Contains(specialPair.Key), specialPair.Key); } context.Response.StatusCode = ExpectedStatusCode; // Some header issues are only visible after calling write and flush. context.Response.Write("Hello World"); context.Response.Body.Flush(); return Task.FromResult(0); }); }
public void Configuration(IAppBuilder app) { // Show an error page app.UseErrorPage(); // Logging component app.Use<LoggingComponent>(); // Configure web api routing var config = new HttpConfiguration(); config.MapHttpAttributeRoutes(); config.Routes.MapHttpRoute( name: "DefaultApi", routeTemplate: "api/{controller}/{id}", defaults: new { id = RouteParameter.Optional } ); // Use web api middleware app.UseWebApi(config); // Throw an exception app.Use(async (context, next) => { if (context.Request.Path.ToString() == "/fail") throw new Exception("Doh!"); await next(); }); // Welcome page app.UseWelcomePage("/"); }
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)); }); }
public void Configuration(IAppBuilder app) { app.UseErrorPage(); app.Use(AddEmployeeClaimBeforeAuthorizationCheck); var config = new HttpConfiguration(); WebApiConfig.Register(config); app.UseAuthorization(options => { options.AddPolicy(ExampleConstants.EmployeeOnlyPolicy, policyBuilder => policyBuilder.RequireClaim(ExampleConstants.EmployeeClaimType)); options.AddPolicy(ExampleConstants.EmployeeNumber6Policy, policyBuilder => policyBuilder.RequireClaim(ExampleConstants.EmployeeClaimType, "6")); options.AddPolicy(ExampleConstants.EmployeeDataAccessPolicy, policyBuilder => policyBuilder.AddRequirements(new HasEmployeeNumberRequirement())); var policyProvider = new DefaultAuthorizationPolicyProvider(options); options.Dependencies.PolicyProvider = policyProvider; options.Dependencies.Service = new DefaultAuthorizationService(policyProvider, new[] { new HasEmployeeNumberHandler() }); }); //config.Filters.Add(new ResourceAccessControl()); app.UseWebApi(config); SwaggerConfig.Register(config); }
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 appBuilder) { IWindsorContainer container = Container.Configure(); HttpConfiguration config = new HttpConfiguration(); config.MapHttpAttributeRoutes(); // Filters //config.Filters.Add(new CustomFilterAttribute()); ModelStateFilterAttribute.Config modelStateConfig = new ModelStateFilterAttribute.Config(); modelStateConfig.ActionWhiteList.Add ( ctrl => ((TaskController)ctrl).CreateAsync(null) ); config.Filters.Add(new ModelStateFilterAttribute(modelStateConfig)); config.Formatters.JsonFormatter.SerializerSettings.NullValueHandling = NullValueHandling.Ignore; config.Formatters.JsonFormatter.SerializerSettings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore; config.Formatters.JsonFormatter.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver(); config.Services.Replace(typeof(IHttpControllerActivator), new WindsorControllerActivator(container)); // MIDDLEWARE appBuilder.UseSample(); appBuilder.UseErrorPage(); appBuilder.UseWebApi(config); }
public void Configuration(IAppBuilder app) { app.UseErrorPage(ErrorPageOptions.ShowAll); // Configure Web API. var config = new HttpConfiguration(); // Web API 路由 config.MapHttpAttributeRoutes(); config.Routes.MapHttpRoute( name: "DefaultApi", routeTemplate: "api/{controller}/{id}", defaults: new { id = RouteParameter.Optional } ); config.Routes.MapHttpRoute("Default", "{controller}/{id}", new { id = RouteParameter.Optional }); // Configure help page //HelpPageConfig.Register(config); //Remove the XM Formatter from the web api config.Formatters.Remove(config.Formatters.XmlFormatter); //Trace & Error log config.EnableSystemDiagnosticsTracing(); #if DEBUG config.Services.Replace(typeof(ITraceWriter), new TraceLogger()); #endif config.Services.Add(typeof(IExceptionLogger), new TraceExceptionLogger()); app.UseWebApi(config); }
public void Configuration(IAppBuilder app) { // Consume bearer tokens var options = new OAuthBearerAuthenticationOptions { // Authn Filter asks for authentication AuthenticationMode = AuthenticationMode.Passive }; app.UseOAuthBearerAuthentication(options); // Configure web api routing var config = new HttpConfiguration(); config.MapHttpAttributeRoutes(); config.Routes.MapHttpRoute( "DefaultApi", "api/{controller}/{id}", new { id = RouteParameter.Optional }); app.UseWebApi(config); // Add error, welcome pages app.UseErrorPage(); app.UseWelcomePage(); }
public void Configuration(IAppBuilder app) { container.Install(new ControllerInstaller(), new DefaultInstaller()); IFileSystem fileSystem = new EmbeddedResourceFileSystem("BotBrown.www.dist"); HttpConfiguration config = new HttpConfiguration(); config.Formatters.JsonFormatter.SupportedMediaTypes.Add(new MediaTypeHeaderValue("text/html")); config.DependencyResolver = new WindsorDependencyResolver(container); config.MapHttpAttributeRoutes(); config.Routes.MapHttpRoute( name: "DefaultApi", routeTemplate: "api/{controller}/{id}", defaults: new { id = RouteParameter.Optional } ); app.UseFileServer(new FileServerOptions { FileSystem = fileSystem, EnableDirectoryBrowsing = true }); #if DEBUG app.UseErrorPage(); #endif //app.UseWelcomePage("/"); }
public void ModuleAndHandlerAsyncException(IAppBuilder app) { app.UseErrorPage(); app.Use(async (context, next) => { try { // Expect async exception from the handler. await next(); Assert.True(false, "Handler exception expected"); } catch (Exception ex) { Assert.IsType<AggregateException>(ex); Assert.IsType<NotFiniteNumberException>(ex.GetBaseException()); } }); RouteTable.Routes.MapOwinPath("/", app2 => { app2.Run(context2 => { TaskCompletionSource<object> tcs = new TaskCompletionSource<object>(); tcs.TrySetException(new NotFiniteNumberException("Handler exception")); return tcs.Task; }); }); }
public void ModuleAndHandlerSyncException(IAppBuilder app) { app.UseErrorPage(); app.Use(async (context, next) => { // Expect async exception from the handler. try { await next(); Assert.True(false, "Handler exception expected"); } catch (NotFiniteNumberException) { } }); RouteTable.Routes.MapOwinPath("/", app2 => { app2.Run(context2 => { // Sync exception should become async before module sees it. throw new NotFiniteNumberException("Handler exception"); }); }); }
public void ExpectedKeys(IAppBuilder app) { app.UseErrorPage(); app.Use((context, next) => { var env = context.Environment; object ignored; Assert.True(env.TryGetValue("owin.RequestMethod", out ignored)); Assert.Equal("GET", env["owin.RequestMethod"]); Assert.True(env.TryGetValue("owin.RequestPath", out ignored)); Assert.Equal("/", env["owin.RequestPath"]); Assert.True(env.TryGetValue("owin.RequestPathBase", out ignored)); Assert.Equal(string.Empty, env["owin.RequestPathBase"]); Assert.True(env.TryGetValue("owin.RequestProtocol", out ignored)); Assert.Equal("HTTP/1.1", env["owin.RequestProtocol"]); Assert.True(env.TryGetValue("owin.RequestQueryString", out ignored)); Assert.Equal(string.Empty, env["owin.RequestQueryString"]); Assert.True(env.TryGetValue("owin.RequestScheme", out ignored)); Assert.Equal("http", env["owin.RequestScheme"]); Assert.True(env.TryGetValue("owin.Version", out ignored)); Assert.Equal("1.0", env["owin.Version"]); Assert.True(env.TryGetValue("owin.RequestId", out ignored)); Assert.False(string.IsNullOrWhiteSpace((string)env["owin.RequestId"])); return Task.FromResult(0); }); }
public void Configuration(IAppBuilder app) { app.UseErrorPage(); app.Map("/signalr", map => { var config = new HubConfiguration { // You can enable JSONP by uncommenting this line JSONP requests are insecure but // some older browsers (and some versions of IE) require JSONP to work cross // domain EnableJSONP = true EnableDetailedErrors = true }; // Turns cors support on allowing everything In real applications, the origins should // be locked down map.UseCors(CorsOptions.AllowAll) .RunSignalR(config); }); XmlConfigurator.Configure(); // Turn tracing on programmatically //GlobalHost.TraceManager.Switch.Level = SourceLevels.Information; }
internal void ModuleAndHandlerAsyncException(IAppBuilder app) { app.UseErrorPage(); app.Use(async(context, next) => { try { // Expect async exception from the handler. await next(); Assert.True(false, "Handler exception expected"); } catch (Exception ex) { Assert.IsType <AggregateException>(ex); Assert.IsType <NotFiniteNumberException>(ex.GetBaseException()); } }); RouteTable.Routes.MapOwinPath("/", app2 => { app2.Run(context2 => { TaskCompletionSource <object> tcs = new TaskCompletionSource <object>(); tcs.TrySetException(new NotFiniteNumberException("Handler exception")); return(tcs.Task); }); }); }
public void Configuration(IAppBuilder app) { app.UseErrorPage(); // Remap '/' to '.\defaults\'. // Turns on static files and default files. app.UseFileServer(new FileServerOptions() { RequestPath = PathString.Empty, FileSystem = new PhysicalFileSystem(@".\"), }); HttpConfiguration config = new HttpConfiguration(); config.MapHttpAttributeRoutes(); //config.Routes.MapHttpRoute("Default", "{controller}/{checkinID}", new { controller = "Checkin", checkinID = RouteParameter.Optional }); //config.Routes.MapHttpRoute("Default3", "{controller}/route/{arg}", new { controller = "Checkin", checkinID = RouteParameter.Optional }); config.Routes.MapHttpRoute("Default", "{controller}/{commitID}", new { controller = "Commit", commitID = RouteParameter.Optional }); config.Routes.MapHttpRoute("Default2", "{controller}", new { controller = "Repository" }); config.Routes.MapHttpRoute("Default3", "{controller}/{user}", new { controller = "User", user = RouteParameter.Optional }); //config.Formatters.XmlFormatter.UseXmlSerializer = true; //config.Formatters.Remove(config.Formatters.JsonFormatter); config.Formatters.Remove(config.Formatters.XmlFormatter); config.Formatters.JsonFormatter.UseDataContractJsonSerializer = true; app.UseWebApi(config); app.UseWelcomePage(); }
public void KnownStagesSpecified(IAppBuilder app) { app.UseErrorPage(); app.Use <BreadCrumbMiddleware>("a", "Authenticate"); AddStageMarker(app, "Authenticate"); app.Use <BreadCrumbMiddleware>("b", "PostAuthenticate"); AddStageMarker(app, "PostAuthenticate"); app.Use <BreadCrumbMiddleware>("c", "Authorize"); AddStageMarker(app, "Authorize"); app.Use <BreadCrumbMiddleware>("d", "PostAuthorize"); AddStageMarker(app, "PostAuthorize"); app.Use <BreadCrumbMiddleware>("e", "ResolveCache"); AddStageMarker(app, "ResolveCache"); app.Use <BreadCrumbMiddleware>("f", "PostResolveCache"); AddStageMarker(app, "PostResolveCache"); app.Use <BreadCrumbMiddleware>("g", "MapHandler"); AddStageMarker(app, "MapHandler"); app.Use <BreadCrumbMiddleware>("h", "PostMapHandler"); AddStageMarker(app, "PostMapHandler"); app.Use <BreadCrumbMiddleware>("i", "AcquireState"); AddStageMarker(app, "AcquireState"); app.Use <BreadCrumbMiddleware>("j", "PostAcquireState"); AddStageMarker(app, "PostAcquireState"); app.Use <BreadCrumbMiddleware>("k", "PreHandlerExecute"); AddStageMarker(app, "PreHandlerExecute"); app.Run(context => { var fullBreadCrumb = context.Get <string>("test.BreadCrumb"); Assert.Equal("abcdefghijk", fullBreadCrumb); return(Task.FromResult(0)); }); }
// This code configures Web API. The Startup class is specified as a type // parameter in the WebApp.Start method. public void Configuration(IAppBuilder appBuilder) { // Configure Web API for self-host. HttpConfiguration config = new HttpConfiguration(); config.MapHttpAttributeRoutes(); config.Routes.MapHttpRoute( name: "DefaultApi", routeTemplate: "api/{controller}/{id}", defaults: new { id = RouteParameter.Optional } ); var jsonFormatter = config.Formatters.OfType <JsonMediaTypeFormatter>().First(); jsonFormatter.SerializerSettings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore; // jsonFormatter.SerializerSettings.NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore; jsonFormatter.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver(); appBuilder.UseErrorPage(); appBuilder.UseCors(Microsoft.Owin.Cors.CorsOptions.AllowAll); appBuilder.UseNinjectMiddleware(CreateKernel); appBuilder.UseNinjectWebApi(config); //appBuilder.UseWebApi(config); }
public void Configuration(IAppBuilder app) { var appOptions = new FileServerOptions { RequestPath = new PathString("/app"), FileSystem = new PhysicalFileSystem("app"), EnableDefaultFiles = true }; appOptions.DefaultFilesOptions.DefaultFileNames.Add("index.html"); appOptions.StaticFileOptions.ServeUnknownFileTypes = true; app.UseFileServer(appOptions); var libsOptions = new FileServerOptions { RequestPath = new PathString("/libs"), FileSystem = new PhysicalFileSystem("libs") }; libsOptions.StaticFileOptions.ServeUnknownFileTypes = true; app.UseFileServer(libsOptions); app.UseErrorPage(); app.MapSignalR(); }
public void Configuration(IAppBuilder app) { // For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=316888 #if DEBUG app.UseErrorPage(); #endif app.UseWelcomePage("/welcome"); HttpConfiguration config = new HttpConfiguration(); config.MapHttpAttributeRoutes(); config.Formatters.Clear(); JsonMediaTypeFormatter json = new JsonMediaTypeFormatter(); json.SerializerSettings = new Newtonsoft.Json.JsonSerializerSettings() { ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore }; config.Formatters.Add(json); //config.Formatters.Add(new JsonMediaTypeFormatter()); app.UseWebApi(config); app.UseSwaggerUi3(typeof(Startup).Assembly, settings => { }); }
public void Configuration(IAppBuilder app) { #if DEBUG app.UseErrorPage(); #endif app.UseWelcomePage("/"); app.Run(context => { if (context.Request.Path == new PathString("/test")) { return(context.Response.WriteAsync("Hello, world")); } if (context.Request.Path == new PathString("/get")) { return(context.Response.WriteAsync("get")); } if (context.Request.Path == new PathString("/set")) { return(context.Response.WriteAsync("set")); } return(context.Response.WriteAsync("what")); }); }
protected virtual void Start(IAppBuilder app, IContainer container) { var config = CreateHttpConfiguration(); ConfigureWebApi(config, container); if (Settings.ShowExceptionDetails) { app.UseErrorPage(new ErrorPageOptions { ShowExceptionDetails = true, ShowSourceCode = true }); } app.UseAutofacMiddleware(container); app.UseStageMarker(PipelineStage.Authenticate); app.UseAutofacWebApi(config); app.UseWebApi(config); RegisterSignalR(container, app); app.UseStageMarker(PipelineStage.MapHandler); RegisterServices(container, app, config); RegisterShutdown(app, container); StartIndexingIfConfigured(container); }
public void Configuration(IAppBuilder app) { app.UseErrorPage(); // Temporary bridge from katana to Owin app.UseBuilder(ConfigurePK); }
public void Configuration(IAppBuilder app) { app.UseErrorPage(); app.UseWelcomePage("/"); GlobalConfiguration.Configuration .UseSqlServerStorage("DefaultConnection", new SqlServerStorageOptions { QueuePollInterval = TimeSpan.FromSeconds(value: 1) }); app.UseHangfireDashboard(); app.UseHangfireServer(); string command; while ((command = Console.ReadLine()) != string.Empty) { if ("job".Equals(command, StringComparison.OrdinalIgnoreCase)) { BackgroundJob.Enqueue(() => Console.WriteLine($"{Guid.NewGuid()} - BackgroundJob job completed successfully ({DateTime.Now})!")); } } //RecurringJob.AddOrUpdate( // () => Console.WriteLine($"{DateTime.Now} Recurring job completed successfully!"), // Cron.Minutely); }
internal void ExpectedKeys(IAppBuilder app) { app.UseErrorPage(); app.Use((context, next) => { var env = context.Environment; object ignored; Assert.True(env.TryGetValue("owin.RequestMethod", out ignored)); Assert.Equal("GET", env["owin.RequestMethod"]); Assert.True(env.TryGetValue("owin.RequestPath", out ignored)); Assert.Equal("/", env["owin.RequestPath"]); Assert.True(env.TryGetValue("owin.RequestPathBase", out ignored)); Assert.Equal(string.Empty, env["owin.RequestPathBase"]); Assert.True(env.TryGetValue("owin.RequestProtocol", out ignored)); Assert.Equal("HTTP/1.1", env["owin.RequestProtocol"]); Assert.True(env.TryGetValue("owin.RequestQueryString", out ignored)); Assert.Equal(string.Empty, env["owin.RequestQueryString"]); Assert.True(env.TryGetValue("owin.RequestScheme", out ignored)); Assert.Equal("http", env["owin.RequestScheme"]); Assert.True(env.TryGetValue("owin.Version", out ignored)); Assert.Equal("1.0", env["owin.Version"]); Assert.True(env.TryGetValue("owin.RequestId", out ignored)); Assert.False(string.IsNullOrWhiteSpace((string)env["owin.RequestId"])); return(Task.FromResult(0)); }); }
public void Configuration(IAppBuilder app) { var url = "http://" + WebRole.GetIP("Consul.SerfLan").ToString() + ":" + WebRole.GetPort("Consul.Http").ToString(); app.UseErrorPage(ErrorPageOptions.ShowAll); app.UseConsulate(new Uri(url)); }
public void SetSpecialHeadersApp(IAppBuilder app) { app.UseErrorPage(new ErrorPageOptions() { ShowExceptionDetails = true }); app.Run(context => { IHeaderDictionary responseHeaders = context.Response.Headers; foreach (var header in _specialHeaders) { responseHeaders[header.Key] = header.Value; Assert.True(responseHeaders.ContainsKey(header.Key), header.Key); Assert.Equal(header.Value, responseHeaders[header.Key]); } Assert.Equal(_specialHeaders.Length, responseHeaders.Count); Assert.Equal(_specialHeaders.Length, responseHeaders.Count()); // All show up in enumeration? foreach (var specialPair in _specialHeaders) { Assert.True(responseHeaders.Select(pair => pair.Key) .Contains(specialPair.Key), specialPair.Key); } context.Response.StatusCode = ExpectedStatusCode; // Some header issues are only visible after calling write and flush. context.Response.Write("Hello World"); context.Response.Body.Flush(); return(Task.FromResult(0)); }); }
void Initialize(IAppBuilder app) { #if DEBUG app.UseErrorPage(); #endif app.UseWelcomePage("/"); }
public void Configuration(IAppBuilder app) { app.UseErrorPage(); app.Map("/raw-connection", map => { // Turns cors support on allowing everything // In real applications, the origins should be locked down map.UseCors(CorsOptions.AllowAll) .RunSignalR<RawConnection>(); }); app.Map("/signalr", map => { var config = new HubConfiguration { // You can enable JSONP by uncommenting this line // JSONP requests are insecure but some older browsers (and some // versions of IE) require JSONP to work cross domain // EnableJSONP = true }; // Turns cors support on allowing everything // In real applications, the origins should be locked down map.UseCors(CorsOptions.AllowAll) .RunSignalR(config); }); // Turn tracing on programmatically GlobalHost.TraceManager.Switch.Level = SourceLevels.All; }
public void Configuration(IAppBuilder app) { #if DEBUG app.UseErrorPage(); #endif app.UseWelcomePage("/"); }
public void Configuration(IAppBuilder app) { #if DEBUG //when things go south app.UseErrorPage(); #endif FileServerOptions fileServerOptions = new FileServerOptions() { RequestPath = PathString.Empty, FileSystem = new PhysicalFileSystem(@".\\public"), }; //In order to serve json files fileServerOptions.StaticFileOptions.ServeUnknownFileTypes = true; fileServerOptions.StaticFileOptions.DefaultContentType = "text"; // Remap '/' to '.\public\'. // Turns on static files and public files. app.UseFileServer(fileServerOptions); app.UseStageMarker(PipelineStage.MapHandler); //Web Api HttpConfiguration config = new HttpConfiguration(); config.MapHttpAttributeRoutes(); //Cause all the cool kids use JSON config.Formatters.JsonFormatter.UseDataContractJsonSerializer = true; config.Formatters.Remove(config.Formatters.XmlFormatter); app.UseWebApi(config); }
/// <summary> /// Configurate the specified application - Magic! /// </summary> /// <param name="app">The application.</param> public void Configuration(IAppBuilder app) { #if DEBUG app.UseErrorPage(); #endif DependencyConfiguration(); this.ConfigureAuth(app); }
public void Configuration(IAppBuilder app) { // Microsoft.Owin.Diagnostics allows for these guys: #if DEBUG app.UseErrorPage(); #endif app.UseWelcomePage("/"); }
public void Configuration(IAppBuilder app) { app.UseErrorPage(); app.MapSignalR(); app.UseNancy(); }
public void Configuration(IAppBuilder app) { app.UseWebApi(Models.Config.GetHttpConfiguration()); app.UseErrorPage(); // the next line is needed for handling the UriPathExtensionMapping... app.UseStageMarker(PipelineStage.MapHandler); app.UseStaticFiles(); app.UseFileServer(true); }
public void Configuration(IAppBuilder app) { app.UseErrorPage(); // See Microsoft.Owin.Diagnostics app.UseWelcomePage("/Welcome"); // See Microsoft.Owin.Diagnostics app.Run(async context => { await context.Response.WriteAsync("Hello world using OWIN TestServer"); }); }
public void Configuration(IAppBuilder appBuilder) { HttpConfiguration config = new HttpConfiguration(); WebApiConfig.Register(config); IdleTimeoutHandler.Register(config); appBuilder.UseWebApi(config); appBuilder.UseErrorPage(); appBuilder.UseWelcomePage("/"); }
public void Configuration(IAppBuilder appBuilder) { HttpConfiguration config = new HttpConfiguration(); WebApiConfig.Register(config); appBuilder.UseWebApi(config); config.Formatters[0] = new JsonStringMediaTypeFormatter(); appBuilder.UseErrorPage(); appBuilder.UseWelcomePage("/"); }
public void Configuration(IAppBuilder app) { #if DEBUG app.UseErrorPage(); #endif app.UseWelcomePage("/welcome"); app.Use(async (ctx, next) => { Debug.WriteLine("IN - [{0}] {1}{2}", ctx.Request.Method, ctx.Request.Path, ctx.Request.QueryString); await next(); if (ctx.IsHtmlResponse()) await ctx.Response.WriteAsync("Added at bottom will be moved into body by good browser"); Debug.WriteLine("OUT - " + ctx.Response.ContentLength); }); app.UseDebugMiddleware(new DebugMiddlewareOptions { OnIncomingRequest = ctx => { var watch = new Stopwatch(); watch.Start(); ctx.Environment["DebugStopwatch"] = watch; }, OnOutgoingRequest = ctx => { var watch = (Stopwatch)ctx.Environment["DebugStopwatch"]; watch.Stop(); Debug.WriteLine("Request took: " + watch.ElapsedMilliseconds + " ms"); } }); app.Map("/mapped", map => map.Run(ctx => { ctx.Response.ContentType = "text/html"; return ctx.Response.WriteAsync("<html><body>mapped</body></html>"); })); //app.UseBeanMiddleware(); //app.Use(async (ctx, next) => //{ // if (ctx.Authentication.User != null && // ctx.Authentication.User.Identity != null && // ctx.Authentication.User.Identity.IsAuthenticated) // { // await next(); // } // else // { // ctx.Authentication.Challenge(AuthenticationTypes.Federation); // } //}); app.UseCornifyMiddleware(new CornifyMiddlewareOptions { Autostart = false }); app.UseKonamiCodeMiddleware(new KonamiCodeMiddlewareOptions { Action = "setInterval(function(){ cornify_add(); },500);" }); app.UseServeDirectoryMiddleware(); }