Issues with execution permissions

Nov 10, 2010 at 1:24 PM
Edited Nov 10, 2010 at 1:37 PM

I'm having a strange issue in just one of my MVC 2 web applications when trying to render Menu or site map path using HTML helpers.

The error is:

"Attempt by method 'MvcSiteMapProvider.External.HttpRequest2.get_AppRelativeCurrentExecutionFilePath()' to access method 'System.Web.Util.UrlPath.MakeVirtualPathAppRelative(System.String)' failed."

or this (it changes randomly):

"[SecurityException: Request failed.]
   System.Security.CodeAccessSecurityEngine.ThrowSecurityException(RuntimeAssembly asm, PermissionSet granted, PermissionSet refused, RuntimeMethodHandleInternal rmh, SecurityAction action, Object demand, IPermission permThatFailed) +168
   System.Security.CodeAccessSecurityEngine.ThrowSecurityException(Object assemblyOrString, PermissionSet granted, PermissionSet refused, RuntimeMethodHandleInternal rmh, SecurityAction action, Object demand, IPermission permThatFailed) +100
   System.Security.CodeAccessSecurityEngine.CheckSetHelper(PermissionSet grants, PermissionSet refused, PermissionSet demands, RuntimeMethodHandleInternal rmh, Object assemblyOrString, SecurityAction action, Boolean throwException) +278
   System.Security.PermissionSetTriple.CheckSetDemand(PermissionSet demandSet, PermissionSet& alteredDemandset, RuntimeMethodHandleInternal rmh) +69
   System.Security.PermissionListSet.CheckSetDemand(PermissionSet pset, RuntimeMethodHandleInternal rmh) +156
   System.Security.PermissionListSet.DemandFlagsOrGrantSet(Int32 flags, PermissionSet grantSet) +33
   System.Security.CodeAccessSecurityEngine.ReflectionTargetDemandHelper(Int32 permission, PermissionSet targetGrant, CompressedStack securityContext) +128
   System.Security.CodeAccessSecurityEngine.ReflectionTargetDemandHelper(Int32 permission, PermissionSet targetGrant) +54"

Suggestions in the exception box suggest going with full trust but I don't actually want that. The Sitemap file I am testing this with is very simple and other sites that work have much more complex sitemap files.

This application was configured to use a custom View engine so I thought this could have something to do with it and removed it. Now that it's using the default ASP.NET MVC View engine it still doesn't work. I also moved all the files in a new VS solution and created a brand new web.config file moving sections manually from the old one to have the new web.config built on top of the default web.config that Visual Studio creates. That didn't help either.

What could be going on here?

Coordinator
Nov 10, 2010 at 2:18 PM

Are the other sites also in mdium trust?

Nov 10, 2010 at 2:20 PM
maartenba wrote:

Are the other sites also in mdium trust?

 Yes. All the sites on this development machine are always created the same.

Coordinator
Nov 12, 2010 at 2:45 PM

Can you please double check if the other sites are also working with the same MvcSiteMapProvider version and medium trust? Problem is that MvcSiteMapProvider needs reflection at some points.

I can do a check and use the previous version of this code under medium trust, but that would re-introduce a node resolving bug that you don't want...

If possible, modify the trust level as described here: http://davestechshop.net/CustomTrustLevelForCommunityServer

Nov 12, 2010 at 7:16 PM

I'm also getting this error. I'm running in medium trust and I can't switch to another trust level since my site will be hosted on a shared environment.

I'm using the latest source code. This is the entire stacktrace:

   at System.RuntimeMethodHandle.PerformSecurityCheck(Object obj, RuntimeMethodHandleInternal method, RuntimeType parent, UInt32 invocationFlags)
   at System.RuntimeMethodHandle.PerformSecurityCheck(Object obj, IRuntimeMethodInfo method, RuntimeType parent, UInt32 invocationFlags)
   at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks)
   at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
   at System.RuntimeType.InvokeMember(String name, BindingFlags bindingFlags, Binder binder, Object target, Object[] providedArgs, ParameterModifier[] modifiers, CultureInfo culture, String[] namedParams)
   at System.Type.InvokeMember(String name, BindingFlags invokeAttr, Binder binder, Object target, Object[] args)
   at MvcSiteMapProvider.External.HttpRequest2.get_AppRelativeCurrentExecutionFilePath()
   at System.Web.Routing.RouteCollection.GetRouteData(HttpContextBase httpContext)
   at MvcSiteMapProvider.DefaultSiteMapProvider.FindSiteMapNode(HttpContext context)
   at System.Web.SiteMapProvider.get_CurrentNode()
   at MvcSiteMapProvider.Web.Html.SiteMapPathHelper.SiteMapPath(MvcSiteMapHtmlHelper helper, String templateName)
   at ASP.views_shared_default_master.__Render__control1(HtmlTextWriter __w, Control parameterContainer)
   at System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children)
   at System.Web.UI.Control.RenderChildren(HtmlTextWriter writer)
   at System.Web.UI.Control.Render(HtmlTextWriter writer)
   at System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter)
   at System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter)
   at System.Web.UI.Control.RenderControl(HtmlTextWriter writer)
   at System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children)
   at System.Web.UI.Control.RenderChildren(HtmlTextWriter writer)
   at System.Web.UI.Control.Render(HtmlTextWriter writer)
   at System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter)

Coordinator
Nov 15, 2010 at 11:33 AM
maartenba wrote:

Problem is that MvcSiteMapProvider needs reflection at some points.

I can do a check and use the previous version of this code under medium trust, but that would re-introduce a node resolving bug that you don't want...

If possible, modify the trust level as described here: http://davestechshop.net/CustomTrustLevelForCommunityServer

 I'm not really keen to do the above because it would make MvcSiteMapProvider less stable...