I have create web api project and getting error like
- <Error>
- <Message>No HTTP resource was found that matches the request URI 'https://localhost:44370/Account/validlogin?userName=admin?userPassword=admin'.</Message>
- <MessageDetail>No action was found on the controller 'Account' that matches the request.</MessageDetail>
- </Error>
Here is my Controller code
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Net;
- using System.Net.Http;
- using System.Web.Http;
-
- namespace WebAPI.Controllers
- {
- public class AccountController : ApiController
- {
-
- [HttpGet]
-
- public HttpResponseMessage ValidLogin(string userName, string userPassword)
- {
- if (userName == "admin" && userPassword == "admin")
- {
- return Request.CreateResponse(HttpStatusCode.OK, value: TokenManager.GenerateToken(userName));
- }
- else
- {
- return Request.CreateErrorResponse(HttpStatusCode.BadGateway, message: "User name and password is invalid");
- }
- }
-
-
-
-
-
- }
- }
And WebApiConfig.cs
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Web.Http;
-
- namespace WebAPI
- {
- public static class WebApiConfig
- {
- public static void Register(HttpConfiguration config)
- {
-
-
-
- config.MapHttpAttributeRoutes();
-
- config.Routes.MapHttpRoute(
- name: "DefaultApi",
- routeTemplate: "{controller}/{action}/{id}",
- defaults: new { id = RouteParameter.Optional }
- );
- }
- }
- }
Now I have run project and pass url like
https://localhost:44370/Account/validlogin?userName=admin?userPassword=admin
and getting error like
- <Error>
- <Message>No HTTP resource was found that matches the request URI 'https://localhost:44370/Account/validlogin?userName=admin?userPassword=admin'.</Message>
- <MessageDetail>No action was found on the controller 'Account' that matches the request.</MessageDetail>
- </Error>
Please give me some suggestion I have tried all like change action name , api route etc.. but not found any solution.