我尝试使用此代码检查用户是否在Application_BeginRequest和Application_AuthenticateRequest中扮演角色,但它不起作用.在BeginRequest中,代码永远不会被命中,并且使用某些请求对其进行身份验证,并且探查器不会显示.
只检查Request.IsLocal工作正常.
if(Request.IsAuthenticated)
{
if(User.IsInRole("Admin");
MiniProfiler.Start();
}
Run Code Online (Sandbox Code Playgroud)
任何想法或为什么它没有工作或更好的方式来做到这一点?
[更新]我接受了芒果,但解除了它,因为我没有完全做到这一点
我做了以下但是探查器最初没有出现.经过几次尝试后,它开始出现,即使我试图以隐身模式访问网站,所以没有cookie.
protected void Application_PostAuthorizeRequest(Object sender, EventArgs e)
{
if (User.IsInRole("Admin"))
{
HttpCookie cookie = HttpContext.Current.Request.Cookies.Get("RoleProfiler");
if (cookie == null)
{
cookie = new HttpCookie("RoleProfiler");
cookie.Value = "yes";
cookie.Expires = DateTime.Now.AddDays(1d);
Response.Cookies.Add(cookie);
}
}
}
Run Code Online (Sandbox Code Playgroud)
我正在检查
protected void Application_BeginRequest(Object sender, EventArgs e)
{
HttpCookie cookie = HttpContext.Current.Request.Cookies.Get("RoleProfiler");
if ((cookie != null) && (cookie.Value == "yes") )
{
MvcMiniProfiler.MiniProfiler.Start();
}
}
Run Code Online (Sandbox Code Playgroud)
并在请求结束时结束.
protected void Application_EndRequest()
{
MvcMiniProfiler.MiniProfiler.Stop();
}
Run Code Online (Sandbox Code Playgroud)
[Update2]结束问题,忽略这一点,我被outputcache所拥有.
我一直在试验这个伟大的工具,Mvc MiniProfiler.
我不希望用大量Step命令乱丢我的所有视图,所以我想在每个动作调用中使用探查器.馊主意?这是我到目前为止所尝试的:
public abstract class BaseController : Controller
{
protected override void OnActionExecuting(ActionExecutingContext filterContext)
{
var profiler = MiniProfiler.Current;
using (profiler.Step("Action: "+filterContext.ActionDescriptor.ActionName))
{
base.OnActionExecuting(filterContext);
}
}
}
Run Code Online (Sandbox Code Playgroud)
但我认为这不是我想做的事情吗?我想我需要启动分析器OnActionExecuting并将其停止OnResultExecuted.考虑到探查器旨在与using声明一起使用,我该如何做到这一点.
我在我的ASP.NET MVC应用程序中设置并使用MiniProfiler.我的控制器通过WCF调用BLL,然后BLL与数据库进行通信.我希望看到WCF服务的分析以及我从Web应用程序中看到的现有分析.是否在所有服务调用中使MiniProfiler成为参数?
将MVC MiniProfiler添加到我的ASP.NET MVC 4项目后,它抱怨要求System.Web.Mvc 3.0.0.0.
有没有办法将MiniProfiler与ASP.NET MVC 4一起使用?
以下程序集重定向已在以下位置定义web.config:
<dependentAssembly>
<assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="0.0.0.0-4.0.0.0" newVersion="4.0.0.0" />
</dependentAssembly>
Run Code Online (Sandbox Code Playgroud) 我正在尝试从nuget和mvc4安装设置miniprofiler,miniprofiler.mvc3和miniprofiler.ef,目标是.net 4.0
它注册了route/mini-profiler-resources/{resourceName},当我使用routedebugger时,这条路线会出现.但是,对这条路线的所有请求都以404s的形式返回.我运气不好因为我正在运行mvc4或者这有点奇怪吗?
<package id="MiniProfiler" version="2.0.2" targetFramework="net40" />
<package id="MiniProfiler.EF" version="2.0.3" targetFramework="net40" />
<package id="MiniProfiler.MVC3" version="2.0.2" targetFramework="net40" />
来自routedebugger(抱歉格式化想象它是一张桌子!)
All Routes
Matches Current Request Url Defaults Constraints DataTokens
False mini-profiler-resources/{filename} controller = MiniProfilerHandler, action = ProcessRequest controller = MiniProfilerHandler, action = ProcessRequest (null)
使用Entity Framework 5,MiniProfiler 2.为MiniProfiler.EF安装Nuget.
按如下方式创建连接
var conn = new EFProfiledDbConnection(DbConnections.GetSqlConnection(), MiniProfiler.Current);
return new MyDbContext(conn, true);
Run Code Online (Sandbox Code Playgroud)
尝试使用DbContext检索数据时,将返回以下错误:
Unable to determine the provider name for connection of type
'StackExchange.Profiling.Data.EFProfiledDbConnection'.`
Run Code Online (Sandbox Code Playgroud)
我尝试将以下内容添加到web.config:
<system.data>
<DbProviderFactories>
<remove invariant="StackExchange.Profiling.Data.ProfiledDbProviderFactory" />
<add name="StackExchange.Profiling.Data.ProfiledDbProviderFactory"
invariant="StackExchange.Profiling.Data.ProfiledDbProviderFactory"
description="StackExchange.Profiling.Data.ProfiledDbProviderFactory"
type="StackExchange.Profiling.Data.ProfiledDbProviderFactory, MiniProfiler, Version=2.0.2.0, Culture=neutral, PublicKeyToken=b44f9351044011a3" />
</DbProviderFactories>
</system.data>
Run Code Online (Sandbox Code Playgroud)
这没有用.我也尝试过使用MiniProfiler.EntityFramework中不同的EFProviderFactories,但是无法使用它们.
如果我尝试运行MiniProfilerEF.Initialize();的App_Start,然后我在尝试访问数据库时,出现以下错误:
如果在Code First模式下使用,使用T4模板为Database First和Model First开发生成的代码可能无法正常工作.要继续使用Database First或Model First,请确保在执行应用程序的配置文件中指定了Entity Framework连接字符串.要使用从Database First或Model First生成的这些类,使用Code First添加任何其他配置,使用属性或DbModelBuilder API,然后删除引发此异常的代码.
卸下DbProviderFactories从web.config部分,并运行MiniProfilerEF.Initialize_EF42();在App_Start在原来的错误.
正如MiniProfiler页面所说的那样,MiniProfilerEF.Initialize()首先只是代码,这似乎不是一种可行的方式.
其他搜索没有给我任何其他的尝试,除了在Web.Config中添加部分.有关如何进行的任何建议?目标是能够使用由Mvc MiniProfiler分析的Model First DbContext.
entity-framework mvc-mini-profiler asp.net-mvc-4 entity-framework-5
我正在尝试使用带有EFCodeFirst的mvc-mini-profiler我正在创建一个DbProfiledConnection并将其传递给构造中的DbContext,如下所示.应用程序继续按预期工作,sql未向Profiler公开.
public class WebContext : DbContext
{
static DbConnection _connection = new SqlConnection(ConfigurationManager.ConnectionStrings["WebContext"].ConnectionString);
static DbConnection _profiledConnection = MvcMiniProfiler.Data.ProfiledDbConnection.Get(_connection);
public WebContext()
: base(_profiledConnection, true)
{
}
Run Code Online (Sandbox Code Playgroud)
我糟透了
我已修改它,以便在我的UnitOfWork中构建我的WebContext时,我传入ProfiledDbConnection
public UnitOfWork()
{
var profiledConnection = MvcMiniProfiler.Data.ProfiledDbConnection.Get(connection);
this.context = new MyContext(profiledConnection);
}
Run Code Online (Sandbox Code Playgroud)
我已经检查过并且在Application_BeginRequest中设置了MiniProfier Current,当我尝试查询数据库时,它会返回ProfiledDbConnection,并在ProfiledDbProviderServices类中抛出错误.
protected override string GetDbProviderManifestToken(DbConnection connection)
{
return tail.GetProviderManifestToken(connection);
}
Run Code Online (Sandbox Code Playgroud)
此方法返回"提供程序未返回ProviderManifestToken字符串".错误
asp.net-mvc entity-framework entity-framework-4.1 mvc-mini-profiler
我通过NuGet添加了Mini Profiler,虽然在一个非常简单的项目中工作很可爱,这是一个很大的现有项目,当然我遇到了一些问题 :(
它将源代码中的正确脚本标记写为
<link rel="stylesheet" type="text/css" href="/mini-profiler-includes.css?v=1.9.0.0">
<script type="text/javascript">
if (!window.jQuery) document.write(unescape("%3Cscript src='/mini-profiler-jquery.1.6.2.js' type='text/javascript'%3E%3C/script%3E"));
if (!window.jQuery || !window.jQuery.tmpl) document.write(unescape("%3Cscript src='/mini-profiler-jquery.tmpl.beta1.js' type='text/javascript'%3E%3C/script%3E"));
</script>
<script type="text/javascript" src="/mini-profiler-includes.js?v=1.9.0.0"></script>
<script type="text/javascript">
jQuery(function() {
MiniProfiler.init({
ids: ["e48fcf61-41b0-42e8-935a-fbb1965fc780","870a92db-89bc-4b28-a410-9064d6e578df","30881949-bfdb-4e3a-9ea5-6d4b73c28c1d","6bca31b8-69d9-48eb-b86e-032f4d75f646","df16838d-b569-47d0-93e6-259c03322394"],
path: '/',
version: '1.9.0.0',
renderPosition: 'left',
showTrivial: false,
showChildrenTime: false,
maxTracesToShow: 15
});
});
</script>
Run Code Online (Sandbox Code Playgroud)
但是当我尝试打开任何文件时,我得到了一个HTTP 404

我确认有一个MiniProfiler.cs不足App_Start并在那里添加一个断点,代码运行,我甚至补充说
#region Mini Profiler
protected void Application_BeginRequest()
{
if (Request.IsLocal)
{
MiniProfiler.Start();
}
}
protected void Application_EndRequest() …Run Code Online (Sandbox Code Playgroud) 这让我发疯,我正在用Firefox和IE测试我的应用程序,在Firefox上运行得很好,但在IE迷你分析中正在进行这5个请求
/Content/mvc-mini-profiler/mini-profiler-includes.css?v=1.9.0.0
/Content/mvc-mini-profiler/mini-profiler-includes.js?v=1.9.0.0
/Content/mvc-mini-profiler/mini-profiler-jquery.tmpl.beta1.js
/mini-profiler-includes.css?v=1.9.0.0
/mini-profiler-includes.js?v=1.9.0.0
我将RouteBasePath设置为〜/ Content/mvc-mini-profiler,但由于某种原因,它也在没有它的情况下发出请求.
我做错了什么或是某种错误?
谢谢.
我在我的asp.net Web API项目中使用迷你探查器,并希望跟踪在自定义DelegatingHandler中运行的某些代码的性能.
MiniProfiler.Current.Step()内部的调用DelegatingHandler不会显示在结果中.同一项目中的其他调用显示正常.
进一步的调查显示,MiniProfiler.Current是从中获取HttpContext.Current的WebRequestProfilerProvider.而HttpContext.Current从调用时为空 DelegatingHandler.
有没有更好的方法来检索MiniProfiler.Current,以便它在处理程序内部工作?