I am using angularJs with webapi and now i want to upload a file on dropbox after login in my webproject on click of a upload button.I have made an api to go the login page of dropbox and after login i want to redirect it to my own page again by redirect url.But when i am calling the webapi its giving the correct url but not redirection to the DropBox page and showing XMLHttpRequest cannot load http://localhost:3371/api/accounts/ConnectDropDown. The request was redirected to 'https://www.dropbox.com/1/oauth2/authorize?response_type=code&client_id=m5e…2F%2Flocalhost%3A3371%2FHome%2FAuth&state=f50e71f99dc54e0da547d85ffbbd4764', which is disallowed for cross-origin requests that require preflight. in the console of the browser.
AngularJs:
var _connectDropbox = function () {
$http.defaults.useXDomain = true;
delete $http.defaults.headers.common['X-Requested-With'];
return $http.get(serviceBase + 'api/accounts/ConnectDropDown').then(function (results) {
return results;
});
};
WebAPi:
[Route("ConnectDropDown")]
public async Task<HttpResponseMessage> ConnectDropDown()
{
var username = User.Identity.Name;
var user = await this.AppUserManager.FindByNameAsync(username);
var appKey = ConfigurationManager.AppSettings["DropboxAppKey"];
var appSecret = ConfigurationManager.AppSettings["DropboxAppSecret"];
var ConnectState = Guid.NewGuid().ToString("N");
user.ConnectState = ConnectState;
IdentityResult addUserResult = await this.AppUserManager.UpdateAsync(user);
var redirect = DropboxOAuth2Helper.GetAuthorizeUri(OAuthResponseType.Code, appKey,RedirectUri,ConnectState);
var response = Request.CreateResponse(HttpStatusCode.Moved);
response.Headers.Location = redirect;
return response;
}
Erro in Console: