public static System.Web.IHtmlString RenderIncludes(RenderPosition?position = null, bool?showTrivial = null, bool?showTimeWithChildren = null, int?maxTracesToShow = null, bool xhtml = false, bool?showControls = null) { var path = VirtualPathUtility.ToAbsolute("~"); return(MiniProfilerHandler.RenderIncludes(Profiler.Current, position, showTrivial, showTimeWithChildren, maxTracesToShow, xhtml, showControls, path) .ToMvcHtmlString()); }
private static int GetRequestResponseHttpStatus(MiniProfilerHandler handler, string resourceName) { using (new HttpSimulator("/mini-profiler-resources/", @"c:\").SimulateRequest(new Uri("http://localhost/mini-profiler-resources"+resourceName))) { handler.ProcessRequest(HttpContext.Current); return HttpContext.Current.Response.StatusCode; } }
private static int GetRequestResponseHttpStatus(MiniProfilerHandler handler, string resourceName) { using (new HttpSimulator("/mini-profiler-resources/", @"c:\").SimulateRequest(new Uri("http://localhost/mini-profiler-resources" + resourceName))) { handler.ProcessRequest(HttpContext.Current); return(HttpContext.Current.Response.StatusCode); } }
public void GivenContext_WhenAResourceIsRequested_ThenTheCorrectHttpStatusCodeIsReturned(string resourceName, int expectedHttpStatus) { // Arrange var sut = new MiniProfilerHandler(); // Act var res = GetRequestResponseHttpStatus(sut, resourceName); // Assert Assert.AreEqual(expectedHttpStatus, res); }
public void GivenContext_WhenAResourceIsRequested_ThenTheCorrectHttpStatusCodeIsReturned(string resourceName, int expectedHttpStatus) { var sut = new MiniProfilerHandler(new MiniProfilerOptions() { ResultsListAuthorize = null }); var res = GetRequestResponseHttpStatus(sut, resourceName); Assert.Equal(expectedHttpStatus, res); }
public void GivenContext_WhenIndexIsRequested_ThenTheCorrectHttpStatusCodeIsReturned(bool isRequestAuthorized, int expectedHttpStatus) { var sut = new MiniProfilerHandler(new MiniProfilerOptions() { ResultsListAuthorize = _ => isRequestAuthorized }); var res = GetRequestResponseHttpStatus(sut, "/results-index"); Assert.Equal(expectedHttpStatus, res); }
public void GivenContext_WhenAResourceIsRequested_ThenTheCorrectHttpStatusCodeIsReturned(string resourceName, int expectedHttpStatus) { // Arrange var sut = new MiniProfilerHandler(); // Act var res = GetRequestResponseHttpStatus(sut, resourceName); // Assert Assert.Equal(expectedHttpStatus, res); }
public void GivenContext_WhenIndexIsRequested_ThenTheCorrectHttpStatusCodeIsReturned(bool isRequestAuthorized, int expectedHttpStatus) { // Arrange var sut = new MiniProfilerHandler(); MiniProfiler.Settings.Results_List_Authorize = request => isRequestAuthorized; // Act var res = GetRequestResponseHttpStatus(sut, "/results-index"); // Assert Assert.AreEqual(expectedHttpStatus, res); }
public void GivenContext_WhenIndexIsRequested_ThenTheCorrectHttpStatusCodeIsReturned(bool isRequestAuthorized, int expectedHttpStatus) { // Arrange var sut = new MiniProfilerHandler(); MiniProfilerWebSettings.ResultsListAuthorize = request => isRequestAuthorized; // Act var res = GetRequestResponseHttpStatus(sut, "/results-index"); // Assert Assert.Equal(expectedHttpStatus, res); }
private static Type GetRequestResponseEncoding(MiniProfilerHandler handler, string resourceName, string encoding) { var headers = new NameValueCollection(); headers.Add("Accept-encoding", encoding); using (new HttpSimulator("/mini-profiler-resources/", @"c:\").SimulateRequest(new Uri("http://localhost/mini-profiler-resources" + resourceName), HttpVerb.GET, headers)) { handler.ProcessRequest(HttpContext.Current); ////return HttpContext.Current.Response.Headers["Content-encoding"]; return(HttpContext.Current.Response.Filter.GetType()); } }
public void GivenContext_WhenAResourceIsRequested_ThenTheCorrectHttpCacheControlIsReturned(string resourceName, HttpCacheability expectedCacheability, int?expectedMaxAgeSeconds) { var sut = new MiniProfilerHandler(new MiniProfilerOptions() { ResultsListAuthorize = null }); var res = GetRequestResponseCacheControl(sut, resourceName); Assert.Equal(expectedCacheability, (HttpCacheability)_cacheability.GetValue(res)); if (expectedMaxAgeSeconds.HasValue) { Assert.Equal(TimeSpan.FromSeconds(expectedMaxAgeSeconds.Value), (TimeSpan)_maxAge.GetValue(res)); } }
void Application_Start(object sender, EventArgs e) { DependencyInjectionConfig.Configure(); AreaRegistration.RegisterAllAreas(); RouteConfig.RegisterRoutes(RouteTable.Routes); FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters); BundlingConfiguration.RegisterBundles(BundleTable.Bundles); ModelBinderConfig.Configure(ModelBinderProviders.BinderProviders); MiniProfilerHandler.RegisterRoutes(); LogManager.GetCurrentClassLogger().Info("Application started"); // no wep api right now // GlobalConfiguration.Configure(WebApiConfig.Register); }
public void GivenContext_WhenIndexIsRequested_ThenTheCorrectHttpStatusCodeIsReturned(string acceptEncoding, Type expectedEncodingFilterType) { // Arrange var sut = new MiniProfilerHandler(); // Act var res = GetRequestResponseEncoding(sut, "includes.js", acceptEncoding); // Assert // due the limitations of the HttpSimulator, we can't access the header values because it needs iis integrated pipeline mode. // instead we return the type of the response filter if (expectedEncodingFilterType == null) { Assert.AreNotEqual(typeof(GZipStream), res); Assert.AreNotEqual(typeof(DeflateStream), res); } else { Assert.AreEqual(expectedEncodingFilterType, res); } }
public void GivenContext_WhenIndexIsRequested_ThenTheCorrectHttpStatusCodeIsReturnedType(string acceptEncoding, Type expectedEncodingFilterType) { // Arrange var sut = new MiniProfilerHandler(new MiniProfilerOptions()); // Act var res = GetRequestResponseEncoding(sut, "includes.min.js", acceptEncoding); // Assert // due the limitations of the HttpSimulator, we can't access the header values because it needs iis integrated pipeline mode. // instead we return the type of the response filter if (expectedEncodingFilterType == null) { Assert.NotEqual(typeof(GZipStream), res); Assert.NotEqual(typeof(DeflateStream), res); } else { Assert.Equal(expectedEncodingFilterType, res); } }
/// <summary> /// Customize aspects of the MiniProfiler. /// </summary> private void InitProfilerSettings() { // A powerful feature of the MiniProfiler is the ability to share links to results with other developers. // by default, however, long-term result caching is done in HttpRuntime.Cache, which is very volatile. // // Let's rig up serialization of our profiler results to a database, so they survive app restarts. var options = ProfilerOptions = new MiniProfilerOptions { // Sets up the WebRequestProfilerProvider with // ~/profiler as the route path to use (e.g. /profiler/mini-profiler-includes.js) RouteBasePath = "~/profiler", // Setting up a MultiStorage provider. This will store results in the MemoryCacheStorage (normally the default) and in SqlLite as well. Storage = new MultiStorageProvider( new MemoryCacheStorage(new TimeSpan(1, 0, 0)), // The RecreateDatabase call is only done for testing purposes, so we don't check in the db to source control. new SqliteMiniProfilerStorage(ConnectionString).RecreateDatabase("create table RouteHits(RouteName,HitCount,unique(RouteName))") ), // Different RDBMS have different ways of declaring sql parameters - SQLite can understand inline sql parameters just fine. // By default, sql parameters will be displayed. //SqlFormatter = new StackExchange.Profiling.SqlFormatters.InlineFormatter(), // These settings are optional and all have defaults, any matching setting specified in .RenderIncludes() will // override the application-wide defaults specified here, for example if you had both: // PopupRenderPosition = RenderPosition.Right; // and in the page: // @MiniProfiler.RenderIncludes(position: RenderPosition.Left) // ...then the position would be on the left that that page, and on the right (the app default) for anywhere that doesn't // specified position in the .RenderIncludes() call. PopupRenderPosition = RenderPosition.Right, // defaults to left PopupMaxTracesToShow = 10, // defaults to 15 // ResultsAuthorize (optional - open to all by default): // because profiler results can contain sensitive data (e.g. sql queries with parameter values displayed), we // can define a function that will authorize clients to see the json or full page results. // we use it on http://stackoverflow.com to check that the request cookies belong to a valid developer. ResultsAuthorize = request => { // you may implement this if you need to restrict visibility of profiling on a per request basis // for example, for this specific path, we'll only allow profiling if a query parameter is set if ("/Home/ResultsAuthorization".Equals(request.Url.LocalPath, StringComparison.OrdinalIgnoreCase)) { return((request.Url.Query).ToLower().Contains("isauthorized")); } // all other paths can check our global switch return(!DisableProfilingResults); }, // ResultsListAuthorize (optional - open to all by default) // the list of all sessions in the store is restricted by default, you must return true to allow it ResultsListAuthorize = request => { // you may implement this if you need to restrict visibility of profiling lists on a per request basis return(true); // all requests are legit in our happy world }, // Stack trace settings StackMaxLength = 256, // default is 120 characters } // Optional settings to control the stack trace output in the details pane .ExcludeType("SessionFactory") // Ignore any class with the name of SessionFactory) .ExcludeAssembly("NHibernate") // Ignore any assembly named NHibernate .ExcludeMethod("Flush"); // Ignore any method with the name of Flush MiniProfilerHandler.Configure(options); MiniProfilerEF6.Initialize(); }
private static Type GetRequestResponseEncoding(MiniProfilerHandler handler, string resourceName, string encoding) { var headers = new NameValueCollection(); headers.Add("Accept-encoding", encoding); using (new HttpSimulator("/mini-profiler-resources/", @"c:\").SimulateRequest(new Uri("http://localhost/mini-profiler-resources"+resourceName), HttpVerb.GET, headers)) { handler.ProcessRequest(HttpContext.Current); ////return HttpContext.Current.Response.Headers["Content-encoding"]; return HttpContext.Current.Response.Filter.GetType(); } }
/// <summary> /// Returns the css and javascript includes needed to display the MiniProfiler results UI. /// </summary> /// <param name="position">Which side of the page the profiler popup button should be displayed on (defaults to left)</param> /// <param name="showTrivial">Whether to show trivial timings by default (defaults to false)</param> /// <param name="showTimeWithChildren">Whether to show time the time with children column by default (defaults to false)</param> /// <param name="maxTracesToShow">The maximum number of trace popups to show before removing the oldest (defaults to 15)</param> /// <param name="xhtml">xhtml rendering mode, ensure script tag is closed ... etc</param> /// <param name="showControls">when true, shows buttons to minimize and clear MiniProfiler results</param> /// <returns>Script and link elements normally; an empty string when there is no active profiling session.</returns> public static IHtmlString RenderIncludes(RenderPosition?position = null, bool?showTrivial = null, bool?showTimeWithChildren = null, int?maxTracesToShow = null, bool xhtml = false, bool?showControls = null) { return(MiniProfilerHandler.RenderIncludes(Current, position, showTrivial, showTimeWithChildren, maxTracesToShow, xhtml, showControls)); }
public MiniProfilerRouteHandler(MiniProfilerHandler miniProfilerHandler) { MiniProfilerHandler = miniProfilerHandler; }