I have created web API that is working fine as i checked that, but the problem is when i call that web API in asp .net website here is a code below of calling web API
protected void btn_search_Click(object sender, EventArgs e)
{
HClient.BaseAddress = new Uri("http://localhost:50653/");
HClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
BoiMember obj = new BoiMember();
obj.CustomerId = txt_customerid.Text.Trim();
obj.AadhaarNo = txt_aadharno.Text.Trim();
obj.CustomerName = txt_name.Text.Trim();
obj.AccountNo = txt_accountno.Text.Trim();
obj.MobileNo = txt_mobile.Text.Trim();
obj.branchcd = Session["BranchCode"].ToString();
obj.ZoneCode = Session["ZoneCode"].ToString();
obj.Campcd = "1";
obj.ind = 1;
obj.SourceType = 2;
obj.UserId = Session["UserName"].ToString();
string uri = "api/BoiMember/GetRecord/";
var response = HClient.GetAsync(uri+obj).Result;
if (response.IsSuccessStatusCode)
{
var GetData = response.Content.ReadAsAsync<IEnumerable<BoiMember>>().Result;
GvdRecords.DataSource = GetData;
GvdRecords.DataBind();
}
else
{
}
}
Where in the API controller named BoiMemberController when I call this web API without parameters it works fine but as I Pass parameters I get the status code 404 Error not found. My web APIConfig.cs has a code
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{action}/{id}",
defaults: new { id = RouteParameter.Optional }
);
uri+obj? That is not going to result in a valid url. What does it produce?objto a string an useduri + '/' + objit would not make much sense - how would you use it?