Abdallah
Abdallah

Reputation: 543

Allowanonymous attribute does not work in asp.net mvc

I am building a web service using web API controller. However, when I try to decorate any of my actions with [allowanonymous] attribute it doesn't work... here is an image

enter image description here

I just would like to know what is goning wrong in here...

Upvotes: 2

Views: 2667

Answers (3)

Alisson Reinaldo Silva
Alisson Reinaldo Silva

Reputation: 10695

Just had to remove this using:

using System.Web.Http;

Because that namespace is for WebAPI, whereas System.Web.Mvc is for MVC Controllers. Using both namespaces in the same file may cause confusions for Authorize and AllowAnonymous, for example.

Upvotes: 1

Usman Khalid
Usman Khalid

Reputation: 3110

On the top of the page, use namespace like:

using System.Web.Mvc;

Upvotes: 1

viggity
viggity

Reputation: 15227

Just fully qualify the name

[System.Web.Mvc.AllowAnonymous]
public ActionResult SomeAction()
{ ...

Upvotes: 3

Related Questions