Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8654535
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T14:48:43+00:00 2026-06-12T14:48:43+00:00

Is it possible to access post or get parameters via the HttpActionContext object? I

  • 0

Is it possible to access post or get parameters via the HttpActionContext object?

I have a set of sensors that loggs data to a web server that provides a REST api. I would like to introduce some sort of authentication/authorization by letting the sensors include their hardware id in the data and then make a lookup in a database to see if the id exists or not. Since the API provides many web api action methods I would ideally like to use a custom authorization attribute

public class ApiAuthorizationFilter : AuthorizeAttribute
{
    protected override bool IsAuthorized(HttpActionContext actionContext)
    {
        return false;
    }
}

How can I access the post/get data from the actionContext?

EDIT:
Example of POST

POST /Api/api/ActionMethod/ HTTP/1.1\r\n
Content-Type: application/json\r\n
Host: localhost\r\n
Accept: */*\r\n
Content-Length:52\r\n
\r\n
{"Id": '121a222bc', "Time": '2012-02-02 12:00:00'}\r\n

Have a nice day!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T14:48:44+00:00Added an answer on June 12, 2026 at 2:48 pm

    Due to its nature the AuthoriseAttribute looks like it is called in the pipeline before the model binders and parameter bindings have run. You also run into issues when you access the Request.Content and read from it… this can only be done once and if you are going to try it in your auth attribute you may break the mediaTypeFormater…

    in WebAPI, the request body (an HttpContent) may be a read-only, infinite, non-buffered, non-rewindable stream.

    Update
    There are different ways of specifying the execution context… http://msdn.microsoft.com/en-us/library/system.web.http.filters.filterscope(v=vs.108).aspx. The AuthoriseAttribute is “Global” and therefore it is hit too early to access the action information.

    Given you want access to the model and parameters you can change your approach slightly and use an OnActionExecuting filter (“Action” filter scope) instead and throw a 401 or 403 based on your validation.

    This filter is called later in the execution process and you therefore have full access to the bound data.

    Very simple example below:

    public class ApiAuthorizationFilter : ActionFilterAttribute
    {
        public override void OnActionExecuting(HttpActionContext actionContext)
        {
            Foo model = (Foo)actionContext.ActionArguments["model"];
            string param1 = (string)actionContext.ActionArguments["param1"];
            int param2 = (int)actionContext.ActionArguments["param2"];
    
            if (model.Id != "1")
                throw new HttpResponseException(System.Net.HttpStatusCode.Forbidden);
    
            base.OnActionExecuting(actionContext);
        }
    }
    

    Example controller:

    public class Foo
    {
        public string Id { get; set; }
        public DateTime Time { get; set; }
    }
    
    public class FoosController : ApiController
    {
        // PUT api/foos/5
        [ApiAuthorizationFilter]
        public Foo Put(int id, Foo model, [FromUri]string param1 = null, int? param2 = null)
        {
            return model;
        }
    }
    

    What the other answers were saying…. they are right you can, if you can access all you need on the URL, get at stuff via the request; however, I think the model and the request content should be left alone:

    var queryStringCollection = HttpUtility.ParseQueryString(actionContext.Request.RequestUri.Query);
    
        //example for param1
        string param1 = queryStringCollection["param1"];
        //example for param2
        int param2 = int.Parse(queryStringCollection["param2"]);
        //Example of getting the ID from the URL
        var id = actionContext.Request.RequestUri.Segments.LastOrDefault();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following code: $r->find('user')->via('post')->over(authenticated => 1); Given that route I can get
How is it possible to simply access to get and post attributes in lift
I have a page web method, and I need to get access to the
Is it possible to access third party menulets via applescript? (Those icons displayed in
Is it possible to access the Data Purge Tool from the Valence API?
Possible Duplicate: How secure is a HTTP POST? Suppose I have a login page
We know that if we pass some values via GET method we will see
Is it possible to somehow get an access token to use the facebook api
Is it even possible to get JSON feed from Reddit and post it in
I have an application which uses offline_access to get permanent access to different pages.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.