1

I have a .Net Mvc4 project, I've added a WebApi Controller and a basic action in for an ajax call.

When I call the method I get:

Inheritance security rules violated while overriding member: 'System.Web.Http.WebHost.Routing.HostedHttpRouteData.get_Route()'. Security accessibility of the overriding method must match the security accessibility of the method being overriden.

I haven't made any custom modifications or set up anything for web Api to work (was I supposed to?)

I noticed the DefaultApi route is in my routeConfig. I'm also using Unity Mvc4 & Unity Web Api packages, (which I've disabled to test if it was causing the issue but doesn't seem to be).

My controller is TestController

action:

public bool ClearAwaitingNotifications()
{}

& ajax call is going to: api/test/clearawaitingnotifications

How can I fix this?

williamsandonz
  • 15,864
  • 23
  • 100
  • 186
  • And lemme guess, you are getting this error on your shared hosting that doesn't support full trust applications? Try adding `[assembly: System.Security.AllowPartiallyTrustedCallers]` to your calling assembly. – Darin Dimitrov Dec 17 '13 at 21:11
  • @DarinDimitrov Nop just on localhost :-). Hmm that caused another error: "Attempt by security transparent method 'MvcWebsite.Bootstrapper.Initialise" assembly is marked with the AllowPartiallyTrustedCallersAttribute, and uses the level 2 security transparency model. Level 2 transparency causes all methods in AllowPartiallyTrustedCallers assemblies to become security transparent by default, which may be the cause of this exception. – williamsandonz Dec 17 '13 at 21:26
  • How about this `[assembly: System.Security.SecurityRules(System.Security.SecurityRuleSet.Level2, SkipVerificationInFullTrust = true)]`? – Darin Dimitrov Dec 17 '13 at 21:35
  • @DarinDimitrov thanks again. No runtime errors this time, but the original exception is still occurring :-( . – williamsandonz Dec 17 '13 at 21:42

1 Answers1

0

My exception occured when hitting controller because:

WebApiConfig.Register(GlobalConfiguration.Configuration);

was never called, although the route existed inside my Routeconfig.cs. I think this occurred because I installed my Mvc4 project using a template, which installs some WebApi stuff and it is all a bit old. I then added this line into Global.ascx and received the same security warning but for this line in Global.ascx.

https://stackoverflow.com/a/18713412/314963 then helped me resolve the issue, and now everything is working. In short, it is because of installing Mvc project with a template, or because one of the libraries in webapi 4 was outdated.

Community
  • 1
  • 1
williamsandonz
  • 15,864
  • 23
  • 100
  • 186