1

I have configured routing like this:

config.Routes.MapHttpRoute( name: "Sales", routeTemplate: "api/{Sales}/{jsonresponce}", defaults: new { controller = "Sales", action = "Postsomething" } ); config.Routes.MapHttpRoute( name: "User", routeTemplate: "api/{User}/{GetDetails}", defaults: new { controller = "User", action = "GetDetails" } ); 

Here is my UserController:

public class UserController : ApiController { userservice objservice = new userservice(); [HttpGet] public CustDetails GetDetails(string Username, string Password, string BillingFeedID) { CustDetails model = new CustDetails(); //checking for encrypted password model.UserName = Username; model.Password = Password; model.BillingFeedID = BillingFeedID; model = objservice.Login(model); //taking merchant configuration data var data = objservice.Getcustomerconfig(model.MerchantID, BillingFeedID); model.LastPosBillID = data.LastPosBillID; model.LastTimeStamp = data.LastTimeStamp; model.SyncStatus = data.SyncStatus; model.SynsTimeInterval = data.SynsTimeInterval; model.DataSorce = data.DataSorce; model.DataAuthentication = data.DataAuthentication; model.DataBaseQuery = data.DataBaseQuery; return model; } } 

I also have a SalesController:

public class SalesController : ApiController { [HttpPost] public async Task<HttpResponseMessage> PostSomething() { StringBuilder sb = new StringBuilder(); try { string jsonData = await Request.Content.ReadAsStringAsync(); // dynamic dataList = JArray.Parse(jsonData); if (File.Exists(@"C:\MCarrots\Umairbills\Umairbills.json")) File.Delete(@"C:\MCarrots\Umairbills\Umairbills.json"); File.Create(@"C:\MCarrots\Umairbills\Umairbills.json").Close(); File.WriteAllText(@"C:\MCarrots\Umairbills\Umairbills.json", jsonData); return Request.CreateResponse(HttpStatusCode.OK, "OK"); } catch (Exception ex) { File.WriteAllText(@"C:\MCarrots\mcarrots\Umairbills.json", ex.ToString()); return Request.CreateResponse(HttpStatusCode.NoContent, ex.ToString()); } } 

When I try to call the GetUserDetails action with this url:

http://localhost:42945/api/User/GetDetails?Username=kay001&Password=kay501&BillingFeedID=KF1 

It is throwing this error:

"Message":"The requested resource does not support http method"

But the POST method in SalesController is working.

1 Answer 1

3

Your route templates seem off. I think they should be:

 config.Routes.MapHttpRoute( name: "Sales", routeTemplate: "api/Sales/{action}", defaults: new { controller = "Sales", action = "Postsomething" } ); config.Routes.MapHttpRoute( name: "User", routeTemplate: "api/User/{action}", defaults: new { controller = "User", action = "GetDetails" } ); 

I changed the route templates so that the controller name is essentially hard-coded, and the action is a placeholder. The action can be left out in this case though, defaulting to GetDetails.

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.