Click here to Skip to main content
15,887,875 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi All,

I am stuck in a problem here is my jquery code:

JavaScript
$(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

C#
protected override System.Threading.Tasks.Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, System.Threading.CancellationToken cancellationToken)
       {

           // Write your Authentication code here
           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))
                   {
                       //check token
                       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
           {
               // Web request cancel reason APP key missing all parameters
               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
Posted
Updated 20-Dec-14 16:55pm
v4
Comments
RaisKazi 20-Dec-14 22:57pm    
You may try by removing debugger keyword from your JS code. Also try by checking Firewall/Proxy settings of your Server.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900