Running MiniProfiler with runAllManagedModulesForAllRequests set to false - asp.net-mvc-3

Recently we upgraded to MiniProfiler version 2.0.1 from v1.7, and since then we have not been able to use it in our MVC3 website because when it tries to get its resources, it instead gets a 404.
An example resource call is:
/mini-profiler-resources/includes.js?v=tNlJPuyuHLy/d5LQjyDuRbWKa0weCpmO3xkO6MH4TtA=
In searching around, most people are suggesting that simply setting runAllManagedModulesForAllRequests should be set to true. For giggles, I went ahead and set it to true, and yes it did work. But that is not an acceptable answer.
How can I keep runAllManagedModulesForAllRequests=false and still use MiniProfiler v2?

I had the same issue - the resources being requested use "static" file extensions (such as .js) and therefore IIS wants to handle them using its static file handler.
Luckily all of the MiniProfiler resources are requested with the path mini-profiler-resources, so you can add the following to your web.config:
<system.webServer>
...
<handlers>
<add name="MiniProfiler" path="mini-profiler-resources/*" verb="*" type="System.Web.Routing.UrlRoutingModule" resourceType="Unspecified" preCondition="integratedMode" />
</handlers>
</system.webServer>
The entry above instructs IIS that any request for the mini-profiler-resources path to be routed through ASP.NET.

As David Duffet says in the comments in the accepted answer, you might also need to add the following entry to your web config. This worked for me:
<system.web>
<httpHandlers>
<add verb="*" type="System.Web.Routing.UrlRoutingModule" path="mini-profiler-resources/*"/>
</httpHandlers>
</system.web>

I had a similar issue and what I did to fix it was change the application pool to 'integrated' and then I added this new line below to my web.config and it then worked.
Here is what the complete web.config looks like now for mini-profiler.
<system.webServer>
<modules runAllManagedModulesForAllRequests="false" />
<validation validateIntegratedModeConfiguration="false"/> <!-- Here is the new line -->
<handlers>
<add name="MiniProfiler" verb="*" type="System.Web.Routing.UrlRoutingModule" path="mini-profiler-resources/*"/>
</handlers>
</system.webServer>

Related

I've created web application with cloud service, windows azure,right now i am deploying my web role on more then 2 environment

I've implemented authentication in my web application, Now problem is like at the time of deployment i've to do some manual settings in web.config file
like; every time if i want to deploy on test then i've to uncomment local testing settings and comment to production setting and vice versa, so is there any way that i can change these settings runtime or dynamically at the time of deployment? because i've lots of environment to publish so every time do manually comment and uncomment of setting is not worthy
<!--LOCAL TESTING-->
<add key="idaFederationMetadataLocation" value="https://login.windows.net/test.onmicrosoft.com/testMetadata/2007-06/testMetadata.xml" />
<add key="idaRealm" value="https://test.onmicrosoft.com/AadTest" />
<add key="idaAudienceUri" value="https://test.onmicrosoft.com/admTest" />
<add key="idaClientID" value="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" />
<add key="idaPassword" value="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx=" />
<!-- PRODUCTION -->
<!-- <add key="idaFederationMetadataLocation" value="https://login.windows.net/test.onmicrosoft.com/testMetadata/2007-06/testMetadata.xml" />
<add key="idaRealm" value="https://test.onmicrosoft.com/AadTest" />
<add key="idaAudienceUri" value="https://test.onmicrosoft.com/admTest" />
<add key="idaClientID" value="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" />
<add key="idaPassword" value="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx=" />-->
So you just need to comment one line in release version of your web.config?
You can use Web.Config Transformation. Add the following line to you Web.Release.config file:
<add key="idaFederationMetadataLocation" xdt:Transform="Remove" xdt:Locator="Match(key)"/>

Role Provider error in web.config

My application is in Asp.Net MVC3, my application was running perfectly but all of a sudden i'm getting an error in my Web.Config in my role manager tag.
Below is my RoleManager tag of web.config
<roleManager defaultProvider="MASSIARoleProvider" enabled="true" cacheRolesInCookie="true">
<providers>
<clear />
<add name="MASSIARoleProvider" type="MASSIA.Helpers.MASSIARoleProvider, MASSIA" connectionStringName="MASSIAEntities" />
</providers>
</roleManager>
Below is the error i'm getting directly when i run my application:
[updated Error Image]
I have a file MASSIARoleProvider.cs in my solution in the directory Helper.
Below is Heirarchy of my RoleProvider file.
--> Massia --> Helpers --> MASSIARoleProvider.cs
My solution was executing perfectly but i'm getting this error all of a sudden.
<roleManager defaultProvider="MASSIARoleProvider" enabled="true" cacheRolesInCookie="true">
<providers>
<clear />
<add name="MASSIARoleProvider" type="MASSIA.Helpers.MASSIARoleProvider" connectionStringName="MASSIAEntities" />
</providers>
</roleManager>
Attemp 2:
Check for your MASSIARoleProvider file and see whether the Solution name and references used are perfectly correct.
Attempt 3:
The last and least recommended.
Create a new solution, if and only if your solution is in the beginning stage and try to reconfigure the RoleProvider. Once it solved the issue for me, I made a new solution, added the existing files to the news solution and executed the new solution and it executed perfectly. I did not made any change to the code, i just included the existing files from the old solution to the new one.

.Net Web API No HTTP resource was found that matches the request URI

I am working on .Net Web API which is working fine in debug as well as on localhost IIS but when i publish this to server it starts giving following error :-
"Message": "No HTTP resource was found that matches the request URI
On server, we have application folder under default site for this API, but it's working fine in application folder under local IIS's default site so that should not be the problem.
Now i tried setting proper verb in handler as specified in following url but didn't work:
HTTP 404 Page Not Found in Web Api hosted in IIS 7.5
Also i have MVC4 installed on server as suggested on following url:
.NET Web Api - 404 - File or directory not found
Also WebDav module, handler may give error so i also tried removing it but it's giving same error.
Here is the Web.config section for module, handler settings :-
<modules runAllManagedModulesForAllRequests="true" />
<validation validateIntegratedModeConfiguration="false" />
<handlers>
<remove name="ExtensionlessUrlHandler-ISAPI-4.0_32bit" />
<remove name="ExtensionlessUrlHandler-ISAPI-4.0_64bit" />
<remove name="ExtensionlessUrlHandler-Integrated-4.0" />
<add name="ExtensionlessUrlHandler-ISAPI-4.0_32bit" path="*." verb="*" modules="IsapiModule"
scriptProcessor="%windir%\Microsoft.NET\Framework\v4.0.30319\aspnet_isapi.dll"
preCondition="classicMode,runtimeVersionv4.0,bitness32" responseBufferLimit="0" />
<add name="ExtensionlessUrlHandler-ISAPI-4.0_64bit" path="*." verb="*" modules="IsapiModule"
scriptProcessor="%windir%\Microsoft.NET\Framework64\v4.0.30319\aspnet_isapi.dll"
preCondition="classicMode,runtimeVersionv4.0,bitness64" responseBufferLimit="0" />
<add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="*" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
</handlers>
I am not playing with routes anywhere. Am i missing something regarding settings/configuration in web.config or server IIS ?
This works for me:
<remove name="WebDAV"/>
I don't know why it is installed on the server. But this seems to have interference with extensionless handlers
From IIS (http://www.iis.net/learn/install/installing-publishing-technologies/installing-and-configuring-webdav-on-iis):
Microsoft released a new WebDAV extension module that was completely
rewritten for Internet Information Services (IIS) 7 and above on
Windows ServerĀ® 2008. This new WebDAV extension module incorporated
many new features that enable Web authors to publish content better
than before, and offers Web administrators more security and
configuration options. Microsoft has released an update to the WebDAV
extension module for Windows ServerĀ® 2008 that provides shared and
exclusive locks support to prevent lost updates due to overwrites.
Another potential reason for this is if the
GlobalConfiguration.Configure(WebApiConfig.Register);
is after
RouteConfig.RegisterRoutes(RouteTable.Routes);
in global.asax.cs
It needs to be before, otherwise the default RouteConfig route 'eats' the WebAPI route - and attempts to map API requests to a controller called API...
Change to:
<validation validateIntegratedModeConfiguration="false" />
<modules>
<remove name="WebDAVModule"/>
</modules>
<handlers>
<remove name="WebDAV"/>
<remove name="ExtensionlessUrlHandler-ISAPI-4.0_32bit" />
<remove name="ExtensionlessUrlHandler-ISAPI-4.0_64bit" />
<remove name="ExtensionlessUrlHandler-Integrated-4.0" />
<add name="ExtensionlessUrlHandler-ISAPI-4.0_32bit" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework\v4.0.30319\aspnet_isapi.dll" preCondition="classicMode,runtimeVersionv4.0,bitness32" responseBufferLimit="0" />
<add name="ExtensionlessUrlHandler-ISAPI-4.0_64bit" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework64\v4.0.30319\aspnet_isapi.dll" preCondition="classicMode,runtimeVersionv4.0,bitness64" responseBufferLimit="0" />
<add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
</handlers>

MVC-Mini-Profiler - Web Forms - 'MiniProfiler' is undefined

I tired to install the MiniProfiler, using the HowTo on http://miniprofiler.com/
This seems to work:
<%= StackExchange.Profiling.MiniProfiler.RenderIncludes() %>
But when I start the site, I get this error message:
'MiniProfiler' is undefined
The problem is in the included MiniProfiler code:
var initMp = function(){
load('/mini-profiler-resources/includes.js?v=6cJT7lsVkH6SxAlFpQstk1/AgtUwMUApXN3pviVvaRE=',function(){
MiniProfiler.init({.....
When I try open http://localhost/mini-profiler-resources/includes.js?v=6cJT7lsVkH6SxAlFpQstk1/AgtUwMUApXN3pviVvaRE= with IE I get an 404.
I even tried this Solution found on stackoverflow but it did not work for me :(
Does anybody know this problem, or know what I can do to fix that?
SOLUTION
I solved the problem by adding the config section from this solution and the "runAllManagedModulesForAllRequests" line:
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
<handlers>
<add name="UrlRoutingModule1" path="mini-profiler*.js" verb="*" type="System.Web.Routing.UrlRoutingModule" resourceType="Unspecified" preCondition="integratedMode" />
<add name="UrlRoutingModule2" path="mini-profiler*.css" verb="*" type="System.Web.Routing.UrlRoutingModule" resourceType="Unspecified" preCondition="integratedMode" />
<add name="UrlRoutingModule3" path="mini-profiler*.tmpl" verb="*" type="System.Web.Routing.UrlRoutingModule" resourceType="Unspecified" preCondition="integratedMode" />
</handlers>
</system.webServer>
The "trick" was to add the line below to get the handlers to work.
<modules runAllManagedModulesForAllRequests="true"/>
You should be able to avoid this issue a bit more concisely (one handler line instead of three) by adding the following to your main web.config file:
<system.webServer>
...
<handlers>
<add name="MiniProfiler" path="mini-profiler-resources/*" verb="*" type="System.Web.Routing.UrlRoutingModule" resourceType="Unspecified" preCondition="integratedMode" />
</handlers>
</system.webServer>

Should Global.asax.cs Application_BeginRequest get called for CSS and JS files?

In ASP.NET MVC3 I notice that Application_BeginRequest gets called for my CSS and JS files as well. My CSS and JS files reside in the /Content and /Scripts folders respectively.
Is this correct? Is there really a need for these files to pass through the managed code pipeline?
The site runs on IIS7 (and the ASP.NET web server).
My modules configuration section looks as follows:
<modules runAllManagedModulesForAllRequests="false">
<remove name="UrlRoutingModule-4.0" />
<add name="UrlRoutingModule-4.0" type="System.Web.Routing.UrlRoutingModule" preCondition="" />
<add name="ErrorLog" type="Elmah.ErrorLogModule, Elmah" preCondition="managedHandler" />
<add name="ErrorMail" type="Elmah.ErrorMailModule, Elmah" preCondition="managedHandler" />
<add name="ErrorFilter" type="Elmah.ErrorFilterModule, Elmah" preCondition="managedHandler" />
</modules>
You should check this answer. Most probably you have same issue. If not then I would check your pipeline mode + handlers configuration.
UPDATE: sorry, just saw that you already have [runAllManagedModulesForAllRequests="false"]. Do you use some profilers or custom virtual path providers?
In my case I use custom virtual path provider to serve files that are embedded into an assembly. For this purpose special configuration is created for a few subdirectories.
Own answer: In the end I could not figure out a way to not let static files go through the MVC pipeline. So I went for a hacky solution where I check the URL extension in Application_PostAuthenticateRequest and just return when static content is being requested (i.e. ".css", ".js" etc.)
Not pretty.

Resources