Hi All,
I am stuck in a problem here is my jquery code:
$(document).ready(function () {
$('#btnSubmit').click(function () {
var companyId = $("#companyname").val();
var startDate = $("#startdate").val();
var endDate = $("#endate").val();
var codeType = $("#typecode option:selected").text();
var record = "companyid=" + companyId + "&startDate=" + startDate + "&enddate=" + endDate + "&type=" + codeType;
var tempurl = 'http://localhost:49987/api/prospectbounce?' + record;
$.ajax({
url: 'http://localhost:49987/api/prospectbounce?' + record,
type: 'GET',
async: false,
dataType: 'json',
success: function (data) {
debugger
var html = '<table border="1" width="100%">';
html += ' <th align="left"><b>Email Address</b></th>'
html += ' <th align="left"><b>Synchronization Key</b></th>'
html += '</tr>'
$.each(data, function (index, value) {
html += '<tr>';
html += '<td align="left">' + value.Email + '</td>';
html += '<td align="left">' + value.SynchronizationKey + '</td>';
html += '</tr>';
});
html += '</table>';
$('#recordShow').html(html);
},
error: function (xhr, status, error) { alert(error); },
beforeSend: setHeader
});
});
});
function setHeader(xhr) {
xhr.setRequestHeader('X-ProspectAppApiKey', '8EJBD8BI:f9a2ac88-6a76-48cf-8357-3f54bb830703');
}
and below is my web API code
protected override System.Threading.Tasks.Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, System.Threading.CancellationToken cancellationToken)
{
IEnumerable<string> monsterApiKeyHeaderValues = null;
if (request.Headers.TryGetValues("X-ProspectAppApiKey", out monsterApiKeyHeaderValues))
{
string[] apiKeyHeaderValue = monsterApiKeyHeaderValues.First().Split(':');
if (apiKeyHeaderValue.Length == 2)
{
var appID = apiKeyHeaderValue[0];
var AppKey = apiKeyHeaderValue[1];
String StrValidationToken = ProspectAccountInfo.IsValidToken(appID, "CRMValidationToken");
Boolean IsValidToken = false;
if (!string.IsNullOrEmpty(StrValidationToken))
{
if (StrValidationToken.ToString().ToLower() == AppKey.ToString().ToLower())
{
IsValidToken = true;
}
}
if (IsValidToken)
{
var userNameClaim = new Claim(ClaimTypes.Name, appID);
var identity = new ClaimsIdentity(new[] { userNameClaim }, "ProspectAppApiKey");
var principal = new ClaimsPrincipal(identity);
Thread.CurrentPrincipal = principal;
if (System.Web.HttpContext.Current != null)
{
System.Web.HttpContext.Current.User = principal;
}
}
else
{
return requestCancel(request, cancellationToken, InvalidToken);
}
}
else
{
return requestCancel(request, cancellationToken, MissingToken);
}
}
else
{
return requestCancel(request, cancellationToken, MissingToken);
}
return base.SendAsync(request, cancellationToken);
}
My problem is that when I send request from cross domain I am unable to process request but with IE it work fine.
Please help me.
Thank & Regards
Mohd Wasif