I have A web API function that returns Facebook Id for the current user, I get the Id from session. The API function displays the id correctly but when I connect to it through a JQuery function it reruns empty string and when I try the Web API function in my browser I can see the result correctly but when I open the source page I can see only empty string Like this:
This is my function code:
public class successController : ApiController
{
[HttpGet]
[Route("api/success")]
public string success()
{
string val = "";
if (System.Web.HttpContext.Current.Session["user"] != null)
{
val = System.Web.HttpContext.Current.Session["user"].ToString();
return val;
}
else
return "";
}
}
2
Answers
are you sure jquery call use get method or post?.
you can install a web sniffer like fiddler to check what differences between each call.
For the same code and logic it is working for me. Instead of cheking user session, I am returning a hard-coded string.
}
Below is my Jquery Code