简体   繁体   中英

Controller Action Not Reaching in ASP.NET Web API

I have a OData web api using ADO.NET Framework in which the controller action is somehow not being reached.

The API correctly receives the HTTP request and parses it to go to the correct action but the action is not reached.

And in return the chrome browser shows the authentication window.

I have been debugging so long but cannot figure out how to solve this.

The controller is (stripped version):

 public class DataController : ODataController
 {
    private readonly DataModel DataAccessModel = new DataModel();


   public DataController()
   {
      ....... 
   }

   [HttpGet, EnableQuery]
   public IQueryable<Record> GetRecord(ODataQueryOptions<Record> options)
   {

       try
       {
           IQueryable<ActivationRequestLog> result;
           try
           {

               result = DataAccessModel.Recordss;
           }
           catch (Exception ex)
           {
              ......
           }
      } 

  } 
}

Can you show how the controller has been registered in the WebApiConfig class?

If you're using the ODataConventionModelBuilder, then you have to follow certain naming conventions for controllers of entity sets.

eg If I register an Airlines entity set of type Airline

        builder.EntitySet<Airline>("Airlines");

....then by default/convention I need to implement

public class AirlinesController : ODataController<Airline>
   {
        [EnableQuery]
        public IQueryable<Airline> Get()
        {
            DB db = Request.GetContext();
            return db.Airlines();
        }
   }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM