如何解决此问题,请在我的webApi中启用Cors

时间:2018-10-25 12:52:31

标签: asp.net-mvc asp.net-core-2.0

从来源“ https:// ....实时站点的URL”访问“ https:// .............”处的XMLHttpRequest已被CORS政策禁止:否请求的资源上显示“ Access-Control-Allow-Origin”标头。

[EnableCors(origins: " http://localhost:50170, https://....url for live site/", headers: "*", methods: "put,delete")]
    public HttpResponseMessage Get(string blobUri)
    {
        var credentials = new StorageCredentials("accountName",
            "api key");
        var blob = new CloudBlockBlob(new Uri(blobUri), credentials);
        var sasParameters = new SharedAccessBlobPolicy()
        {
            SharedAccessExpiryTime = DateTime.UtcNow.AddMinutes(20),
            Permissions = SharedAccessBlobPermissions.Write
        };

        var sasToken = blob.GetSharedAccessSignature(sasParameters);
        var returnValue = blob.Uri.AbsoluteUri + sasToken;
        return ReturnText(returnValue);
    }

 [HttpPost]
    [EnableCors(origins: " http://localhost:50170, https://....url for live site/", headers: "*", methods: "post")]
    public HttpResponseMessage Done()
    {
        HttpContent requestContent = Request.Content;
        var stringContent = requestContent.ReadAsStringAsync().Result;
        var query = HttpUtility.ParseQueryString(stringContent);
        return ReturnText("{\"success\":true}");
    }

0 个答案:

没有答案