Rajesh Gami

Rajesh Gami

  • 79
  • 24.4k
  • 1.3m

In Web API : No action found on Account controller

Aug 21 2020 12:11 AM
I have create web api project and getting error like
  1. <Error>  
  2. <Message>No HTTP resource was found that matches the request URI 'https://localhost:44370/Account/validlogin?userName=admin?userPassword=admin'.</Message>  
  3. <MessageDetail>No action was found on the controller 'Account' that matches the request.</MessageDetail>  
  4. </Error>  
Here is my Controller code
  1. using System;    
  2. using System.Collections.Generic;    
  3. using System.Linq;    
  4. using System.Net;    
  5. using System.Net.Http;    
  6. using System.Web.Http;    
  7.     
  8. namespace WebAPI.Controllers    
  9. {    
  10.     public class AccountController : ApiController    
  11.     {    
  12.       
  13.         [HttpGet]    
  14.          
  15.         public HttpResponseMessage ValidLogin(string userName, string userPassword)    
  16.         {    
  17.             if (userName == "admin" && userPassword == "admin")    
  18.             {    
  19.                 return Request.CreateResponse(HttpStatusCode.OK, value: TokenManager.GenerateToken(userName));    
  20.             }    
  21.             else    
  22.             {    
  23.                 return Request.CreateErrorResponse(HttpStatusCode.BadGateway, message: "User name and password is invalid");    
  24.             }    
  25.         }    
  26.     
  27.         //public string get()    
  28.         //{    
  29.         //    return "value";    
  30.         //}    
  31.     }    
  32. }  
And WebApiConfig.cs
  1. using System;    
  2. using System.Collections.Generic;    
  3. using System.Linq;    
  4. using System.Web.Http;    
  5.     
  6. namespace WebAPI    
  7. {    
  8.     public static class WebApiConfig    
  9.     {    
  10.         public static void Register(HttpConfiguration config)    
  11.         {    
  12.             // Web API configuration and services    
  13.     
  14.             // Web API routes    
  15.             config.MapHttpAttributeRoutes();    
  16.     
  17.             config.Routes.MapHttpRoute(    
  18.                 name: "DefaultApi",    
  19.                 routeTemplate: "{controller}/{action}/{id}",    
  20.                 defaults: new { id = RouteParameter.Optional }    
  21.             );    
  22.         }    
  23.     }    
  24. }  
Now I have run project and pass url like
 
https://localhost:44370/Account/validlogin?userName=admin?userPassword=admin
 
and getting error like
  1. <Error>  
  2. <Message>No HTTP resource was found that matches the request URI 'https://localhost:44370/Account/validlogin?userName=admin?userPassword=admin'.</Message>  
  3. <MessageDetail>No action was found on the controller 'Account' that matches the request.</MessageDetail>  
  4. </Error>  
Please give me some suggestion I have tried all like change action name , api route etc.. but not found any solution.

Answers (4)