MVCSiteMap still doesn't work in medium-trust mode

Jun 27, 2010 at 5:11 PM

From reading other discussions, it seemed that the issue with medium-trust environments had been fixed.

Not so!

I'm trying to get a very basic, minimal ASP.NET MVC website working on shared hosting (GoDaddy).

When using the latest version of MvcSiteMap, I get the following error:

Server Error in '/skilldriven' Application.

Security Exception

Description: The application attempted to perform an operation not allowed by the security policy.  To grant this application the required permission please contact your system administrator or change the application's trust level in the configuration file. 

Exception Details: System.Security.SecurityException: That assembly does not allow partially trusted callers.

Source Error: 

Line 40: 	<footer>
Line 41: 		<p>
Line 42: 			&copy; Copyright <%= Model.CompanyName %> <%= DateTime.Now.Year %> <b>|</b> 
Line 43: 			ABN 00 000 000 000 <b>|</b> 
Line 44: 			<a href="mailto:info@skilldriven.com">info@skilldriven.com</a> <b>|</b> 


Source File: d:\hosting\4594209\html\skilldriven\Views\Shared\Public.Master    Line: 42 

 

Jun 29, 2010 at 10:31 AM

This should really be added to AssemblyInfo.cs:

[assembly: AllowPartiallyTrustedCallers]

Jun 30, 2010 at 12:54 PM
This discussion has been copied to a work item. Click here to go to the work item and continue the discussion.
Jul 2, 2010 at 5:24 AM

Unfortunately, another problem has come up - 

In order to make it work under medium trust, I had to set 'scanAssembliesForSiteMapNodes' = 'false' in the config section.

After doing this, the navigation isn't setting 'selected' class on the appropriate item, given the controller. It's always setting the first navigation item to 'selected', even if I was in the 2nd or 3rd item.

Can anything be done to fix this? I tried researching what 'scanAssembliesForSiteMapNodes', but the documentation is scarce.

Jul 2, 2010 at 6:59 AM

scanAssembliesForSiteMapNodes does just what the name implies: it will scan your assemblies to check if something is attributed with [MvcSiteMap(....)]. This will have to be disabled in medium trust I'm affraid, and nodes will have to be defined in sitemap XML.

Jul 2, 2010 at 7:04 AM
Edited Jul 2, 2010 at 7:05 AM

@maartenba, That's totally fine, and in fact, I *want* to define all my nodes in the sitemap.xml file.

And that's what I've done, and it all works.

Except that, as I said, it's not highlighting the selected node properly.

For example, say I browse to "Persons/Jonathan" and I have a node in my sitemap XML like this:

<sitemapNode controller="Persons" action="Jonathan" />

It will show that item in the navigation, but it just won't mark it as "selected". It will *always* mark the first item as selected, even if the first item isn't actually selected.

I checked View->Source just to make sure this wasn't a CSS issue. It isn't - there simply isn't any "selected" class on the HTML.

Even though I passed "selected" as a parameter to the 'Menu' helper method.

Anything I can do to fix this?

Jul 2, 2010 at 7:10 AM

Actually, I think I know why this is failing.

Forgot to mention that I'm not just using Controller and Action settings in my sitemap.xml - I'm also using custom parameters.

For example:

<mvcSiteMapNode title="Clients" controller="Articles" action="Index" articleName="clients" />

Perhaps it can't differentiate by "articleName", because that would rely on reflection, which would require full trust, thus it doesn't work in medium trust?

Is that the reason?

Jul 20, 2010 at 7:30 AM

That will indeed be the problem. I can fix this, but that would mean copying more than half of the ASP.NET MVC source code. Not really planning on maintaining that...