3

I am configuring my server in various modes and I am setting the modes of the application from a config file. So, say if I run my HTTP server is in mode "X", I want clients to get "HTTP STATUS 200 and don't execute any logic" if they hit a valid endpoint. and if the server is in mode "Y" all endpoints should perform the logic and return the status as per the request processing

[Route("api/todo")]
public class TodoController : Controller{

        //if in mode "Y"
        [HttpGet("{id}", Name = "GetTodo")]
        public IActionResult GetById(long id)
        {
            var item = _todoRepository.Find(id);
            if (item == null)
            {
                return NotFound();
            }
            return new ObjectResult(item);
        }

       //if in mode "X"
       [HttpGet("{id}", Name = "GetTodo")]
       public IActionResult GetById(long id){
         return Ok();
       }

}

Is there a way using filter that can return OK to the client without getting inside of the action method?

EDIT: When i say modes, I mean like modes like "production", "testing", "staging". [like we have different db connection strings for all these modes] So, I have a mode called "X" [and if my server is running on mode "X"], any client who hits the endpoints exposed by me will get success.

7
  • Can you be much clear on what do you mean by modes? Commented May 22, 2017 at 16:57
  • When i say modes, I mean like modes like "production", "testing", "staging". [like we have different db connection strings for all these modes] So, I have a mode called "X" [and if my server is running on mode "X"], any client who hits the endpoints exposed by me will get success. Commented May 22, 2017 at 17:13
  • Where are you configuring it? Commented May 22, 2017 at 17:16
  • I will be reading a variable from the config file, which will tell me the current mode. Something like: string mode = ConfigurationManager.AppSettings[mode]; Commented May 22, 2017 at 17:18
  • 1
    This might help: stackoverflow.com/questions/25292907/… Commented May 22, 2017 at 17:41

1 Answer 1

3

Yes, you can do this by using a validation middleware. I don't get exactly what you mean by running the HTTP server in mode X or mode Y, so you need to adapt your code.

For example, take a look at the picture below:

enter image description here

You'll need to implement something like the "Authorization middleware" in the picture. You just need to return the request with HTTP 200 OK before if gets on the controllers (app.UseMvc() in the Startup.cs).

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

1 Comment

I am trying doing it using middleware, will get back in case of a doubt.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.