public WebRequestProfilerTests()
 {
     _provider = WebRequestProfilerProvider.Setup();
 }
 public WebRequestProfilerTests()
 {
     _provider = new WebRequestProfilerProvider();
 }
Beispiel #3
0
        /// <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.

            // Setting up a MultiStorage provider. This will store results in the MemoryCacheStorage (normally the default) and in SqlLite as well.
            MiniProfiler.Settings.Storage = new MultiStorageProvider(
                new MemoryCacheStorage(new TimeSpan(1, 0, 0)),
                new SqliteMiniProfilerStorage(ConnectionString)
                );

            // Different RDBMS have different ways of declaring sql parameters - SQLite can understand inline sql parameters just fine.
            // By default, sql parameters won't be displayed.
            MiniProfiler.Settings.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:
            //    MiniProfiler.Settings.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.
            MiniProfiler.Settings.PopupRenderPosition  = RenderPosition.Right; // defaults to left
            MiniProfiler.Settings.PopupMaxTracesToShow = 10;                   // defaults to 15

            // Optional settings to control the stack trace output in the details pane
            MiniProfiler.Settings.ExcludeType("SessionFactory"); // Ignore any class with the name of SessionFactory
            MiniProfiler.Settings.ExcludeAssembly("NHibernate"); // Ignore any assembly named NHibernate
            MiniProfiler.Settings.ExcludeMethod("Flush");        // Ignore any method with the name of Flush
            MiniProfiler.Settings.StackMaxLength = 256;          // default is 120 characters

            // Sets up the WebRequestProfilerProvider with
            // ~/profiler as the route path to use (e.g. /profiler/mini-profiler-includes.js)
            WebRequestProfilerProvider.Setup("~/profiler",
                                             // 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.
                                             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
                                             request =>
            {
                // you may implement this if you need to restrict visibility of profiling lists on a per request basis
                return(true);    // all requests are kosher
            });
        }