0

I have an MVC project which has MVC App and WebApi in it. T

The WebApi is used by the MVC App to do the business logic and return objects. I had never tried to access to the Web Api with Chrom or somethingelse. But now, we have decided WebApi to be accessible by all our customer via HTTP protocol, I mean it should be accesible with Chrome like a regular WebApi projects.

What should I do to make the WebApi public to all? Should I add a TAG above of the function?

here are important parts of my ApiController which should be public

public class CustomerApiController : ApiController
{

[LocalizationWebApi]
[SessionControlWebApi]
[ScreenAccess(SCREEN_ACCESS.Show)]
public JsonResult<CustomerOrderFormSearchResult> CustomerOrderFormSearch(CustomerOrderFormSearchModel Model_)
{

    CustomerOrderFormSearchResult ret_ = new CustomerOrderFormSearchResult();
    ret_.Errors.Add(ResourceExtensions.Language("SHARED_MESSAGE_SESSIONCLOSED"));
        return Json(ret_, IgnoreEntityProxyContractResolver.Create());
}

}
3
  • If I get your question correctly, You want to access you web api using browser? If yes just configure the route properly In your case it might be configured properly run the project and access the route. you will get your response Commented Jul 13, 2016 at 19:50
  • yes, but do I need to add [HttpPost] Commented Jul 13, 2016 at 20:01
  • 1
    Yes You need to add. But in your case you need to add [HttpGet] Commented Jul 13, 2016 at 20:11

1 Answer 1

2

As I think you need to add the action verb with you controller action method example [HttpPost],[HttpGet],[HttpPut] etc. in your case you need to use [HttpGet] because it is plane get call. Modify your controller like

public class CustomerApiController : ApiController
{
[LocalizationWebApi]
[HttpGet]
[SessionControlWebApi]
[ScreenAccess(SCREEN_ACCESS.Show)]
public JsonResult<CustomerOrderFormSearchResult> CustomerOrderFormSearch(CustomerOrderFormSearchModel Model_)
{
       CustomerOrderFormSearchResult ret_ = new CustomerOrderFormSearchResult();
       ret_.Errors.Add(ResourceExtensions.Language("SHARED_MESSAGE_SESSIONCLOSED"));
       return OK(ret_);
       //Better to return Ok in your search result
      // If you want validation use NotFound() or something slimier to that 
 }
}

Always be careful about the route configuration of your api.

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

Comments

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.