web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

MVC Azure + AjaxCall + microsofttranslator + Response to preflight request doesn't pass access control check: It does not have HTTP ok status

(0) ShareShare
ReportReport
Posted on by 2,287

HI All,

I have Created a MicrosoftTranslator in MVC and i have hosted that in Azure,

[HttpGet]
[Route("~/CyrillicCharacterConversion/{wordtobeConverted}")]
public async Task<string> accountLockUnlock(string wordtobeConverted)
{try{var translatedText = "";

while (true)

{

translatedText = await Translate(wordtobeConverted, "en");

return translatedText;

}}
catch (Exception ex)
{
}
}

public static async Task<string> Translate(string text, string language)
{var encodedText = WebUtility.UrlEncode(text);
var uri = "api.microsofttranslator.com/.../Translate" +$"to={language}&text={encodedText}";

var result = awaitclient.GetStringAsync(uri);

return XElement.Parse(result).Value;
}

private const string key = "KeyID";

private static readonly HttpClient client = new HttpClient
{
DefaultRequestHeaders = { { "Ocp-Apim-Subscription-Key", key } }
};

After Hosting if try to call from PostMan, am getting Proper Result
Sample Calling : azurewebsites.net/.../Ciao
Result we are getting as "HELLO", So no issue till here

If i try calling the same URL azurewebsites.net/.../Ciao from Ajax call am getting " Response to preflight request doesn't pass access control check: It does not have HTTP ok status"

My Ajax Call:

var settings = {
"async": true,
"crossDomain": true,
"url": "azurewebsites.net/.../Ciao",
"method": "GET",
"headers": {
"cache-control": "no-cache",
"Access-Control-Allow-Headers": "*"
}
}

$.ajax(settings).done(function (response) {
console.log(response);
});

Could any one help me here?

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Kokulan Profile Picture
    18,054 on at

    Hi

    Your question is not much related to Dynamics CRM or Dynamics 365,  you might get better answer if you post on MVC or .NET forums but just wanted to check if your MVC/Web Api has Cross Origin enabled.

    please follow the link below and make sure on server side CORS are enabled

    docs.microsoft.com/.../enabling-cross-origin-requests-in-web-api

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans