I have an MVC website that uses kendo controls in many of the views.
The code -
View
@(Html.Kendo().MultiSelectFor(model => model.certificateIds)
.HtmlAttributes(new { style = "width: 140%" })
.DataTextField("CertificateName")
.DataValueField("CertificateId")
.Placeholder("Select Certificates")
.DataSource(source =>
{
source.Read(read =>
{
read.Action("GetCertificates", "Account");
});
})
)
Controller
[HttpGet]
[OutputCache(Duration = int.MaxValue, Location = OutputCacheLocation.Any)]
public JsonResult GetCertificates()
{
return Json(_accountsManager.GetAllCertificates(), JsonRequestBehavior.AllowGet);
}
The problem - The read.Action() should get all the certificates for me, and 9 out of 10 times it does. But every now and then, when the session needs to replenished the application redirects the call to https://login.windows.net/ (I am using Azure AD for authentication). The redirection causes the whole read action to fail and no data is loaded in my dropdown.
The exact error
XMLHttpRequest cannot load https://login.windows.net/72...47/oauth2/autho…Rm...jc1. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'https://xyz-test.cloudapp.net' is therefore not allowed access.
I know this type of error usually happens when its a CORS issue, but I dont think this one is that. Similar redirections for authentication happen in other parts of the website and they work just fine.