User-712926555 posted
Hi,
This is my first Project in web api. I am creating web api for User Login
In my web api 2 Controller like as follows
using MyServices.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
namespace MyServices.Controllers
{
public class UserController : ApiController
{
[Route("api/User")]
[HttpGet]
public HttpResponseMessage AppLogin(String userName, String passWord)
{
Admin_AppUserBLL objusr = Admin_AppUserBLL.GetAdmin_AppUserBLL(userName);
if (objusr != null)
{
if (objusr.Password == passWord)
{
objusr.Message = "valid username";
}
else
{
objusr = new Admin_AppUserBLL();
objusr.Message = "username or password is invalid";
objusr.Status = 0;
}
}
else
{
objusr = new Admin_AppUserBLL();
objusr.Message = "username or password is invalid";
objusr.Status = 0;
}
//return objusr.ToString();//
HttpResponseMessage res = Request.CreateResponse(HttpStatusCode.OK, objusr);
return res;
}
}
}
While consuming this service
http://localhost:50007/api/User/AppLogin?userName=123&passWord=123
It shows error like No action was found on the controller 'User' that matches the request.
In my webApiConfig
public static void Register(HttpConfiguration config)
{
// Web API configuration and services
// Web API routes
config.MapHttpAttributeRoutes();
// config.Routes.MapHttpRoute(
// name: "DefaultApi",
// routeTemplate: "api/{controller}/{id}",
// defaults: new { id = RouteParameter.Optional }
//);
I Have tried like as follows, but still same issue
// config.Routes.MapHttpRoute(
// name: "AppLogin",
// routeTemplate: "api/{User}/{name}/{password}",
// defaults: new { name = RouteParameter.Optional, password = RouteParameter.Optional }
// );
}
How to solved it