0

I have sample ASP.NET Web API with get method, I have prefixed a [Authorize] attribute on top of the method. Can I please know how should I call this method from browser or fiddler? Also, I am hosting these API's on Windows Azure

public class ValuesController : ApiController
{
    // GET api/values
    [Authorize]
    public IEnumerable<string> Get()
    {
        return new string[] { "value1", "value2" };
    }
}

1 Answer 1

1

Depending on the type of authorization you are using there might be different ways. But if you are using default routing you could call your method at the following url:

/api/values

You might of course need to pass additional headers depending on the authorization mechanism you choose. The [Authorize] attribute doesn't do anything unless you have configured some authorization. You may take a look at the following article for an example of how you could use tokens to authenticate your users.

Sign up to request clarification or add additional context in comments.

3 Comments

Thanks for the response , The article is very informative , I am trying to implement CustomHttpsAttribute , should i register in filterconfig class?
No, FilterConfig is used to declare global filters for your ASP.NET MVC controllers. It has nothing to do with the Web API. If you want to configure something for the Web API you should do it on the proper configuration object. This should happen in the ~/App_Start/WebApiConfig.cs file.
I am adding following code in WebAPIConfig file config.Filters.Add(new CustomHttpsAttribute());

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.