Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

'AllowAnonymous' could not be found

Everything worked fine until I installed (Package Manager Console) the postal package, then uninstalled and installed an older version.

Now I get an error where it previously was not. Error:

The type or namespace name 'AllowAnonymous' could not be found (are you missing a using directive or an assembly reference?)

Who knows how to fix this?

like image 851
user3128303 Avatar asked Jun 24 '14 15:06

user3128303


People also ask

How does AllowAnonymous work?

[AllowAnonymous] bypasses all authorization statements. If you combine [AllowAnonymous] and any [Authorize] attribute, the [Authorize] attributes are ignored. For example if you apply [AllowAnonymous] at the controller level, any [Authorize] attributes on the same controller (or on any action within it) is ignored.

Which attribute will ensure that all users can access a specific controller action?

One of the new features in ASP.NET MVC 4 is the AllowAnonymous Attribute that helps you secure an entire ASP.NET MVC 4 Website or Controller while providing a convenient means of allowing anonymous users access to certain controller actions, like the login and register Actions.


1 Answers

Probably you are missing the reference to System.Web.Http assembly in your project?

So you need to:

  • Add the reference to System.Web.Http;
  • Add using System.Web.Http; to your controller;

To add Reference you need to do next steps:

  • In Solution Explorer, right-click the project node and click Add Reference.
  • In the Add Reference dialog box, select the tab Assemblies, and enter System.Web.Http into search on the right side.
  • Select the component System.Web.Http, and then click OK.

Link:

How to: Add or Remove References By Using the Add Reference Dialog Box

like image 101
Dmitry Zaets Avatar answered Sep 20 '22 11:09

Dmitry Zaets