Quantcast
Channel: Web API
Viewing all articles
Browse latest Browse all 4850

call a web api method in ASP.NET MVC

$
0
0

Hi,

In my ASP.NET MVC project, every call/request for Database query is done via web api.

So i can say that simply my MVC application talks to web api for any DB related queries

MVC application and web api are two different projects/solutions

I have a login page, when user submits the user name and password then the below action method is called

[HttpPost]
public ActionResult Login(string txtUserName, string txtPwd)
{
ViewBag.txtUserName = txtUserName;

// here i want to call the web api method to validate the user

//and i want the thread should be waited untill a response has come from web api.

if (isValidUser)
return RedirectToAction("Index");
else
return RedirectToAction("Login");
}

and the corresponding web api method is

[HttpGet]
[Route("api/Employee/ValidateUser/{userName}/{pwd}")]
public HttpResponseMessage ValidateUser(string userName, string pwd)
{
EmployeeBAL objempDetails = new EmployeeBAL();
bool empDetails = objempDetails.ValidateUser(userName,pwd);
HttpStatusCode status = (empDetails ? HttpStatusCode.OK : HttpStatusCode.Unauthorized);
var response = Request.CreateResponse<bool>(status, empDetails);
return response;
}

How can i do it?

Please can any one help me out on this

Thanks,

Vijay Devd


Viewing all articles
Browse latest Browse all 4850

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>