500内部服务器错误。CORS

我收到 500 服务器错误:


https://screencast.com/t/n7VRzxSSi6


Cors 已经在 web api 上启用。


https://screencast.com/t/3Fl70yX0awO


web api 代码是这样的:


public class TenantController : ApiController

    {

        public async Task<List<Tenant>> GetTenants()

        {

            var tenantStore = CosmosStoreFactory.CreateForEntity<Tenant>();

            return await tenantStore.Query().Where(x => x.TenantId != null ).ToListAsync();


        }


        public async Task<IHttpActionResult> GetTenant(string tenantId)

        {

            var tenantStore = CosmosStoreFactory.CreateForEntity<Tenant>();

            var tenant = await tenantStore.Query().FirstOrDefaultAsync(x => x.TenantId == tenantId);

            if (tenant == null)

            {

                return NotFound();

            }

            return Ok(tenant);

        }


        public async Task<IHttpActionResult>  PutTenant([FromBody]Tenant tenant, HttpPostedFile certificateFile)

        {

            CloudStorageAccount storageAccount = CloudStorageAccount.Parse(ConfigurationManager.AppSettings["AzureStorageKey"].ToString());

            // Create the blob client.

            CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();


            // Retrieve reference to a previously created container.

            CloudBlobContainer container = blobClient.GetContainerReference(ConfigurationManager.AppSettings["certificatesContainer"].ToString());


            // Retrieve reference to a blob named "myblob".

            CloudBlockBlob blockBlob = container.GetBlockBlobReference("myblob");


            // Create or overwrite the "myblob" blob with contents from a local file.

            blockBlob.Properties.ContentType = certificateFile.ContentType;

            blockBlob.UploadFromStream(certificateFile.InputStream);


            var tenantStore = CosmosStoreFactory.CreateForEntity<Tenant>();

            tenant.CertificatePath = blockBlob.Uri;


我在发布后附加了调试器,但代码从未在 Visual Studio 中被命中


MMMHUHU
浏览 139回答 1
1回答

忽然笑

要初始化你的状态this.state = { TenantId: '', TenanrUrl:'', TenantPassword:''};,但你正在使用tenantid,tenanturl以及tenantpassword在你的代码。由于tenantid、tenanturl和tenantpassword最初不在您的状态,您将开始提供undefined您的输入,直到您调用setState并更新它。这将使输入从不受控制变为受控制。您可以通过更改初始状态修复它以默认值tenantid,tenanturl以及tenantpassword代替:constructor(props) {&nbsp; super(props);&nbsp; this.state = { tenantid: '', tenanturl: '', tenantpassword: '' };&nbsp; this.handleChangeTenantUrl = this.handleChangeTenantUrl.bind(this);&nbsp; this.handleChangeTenantPassword = this.handleChangeTenantPassword.bind(this);&nbsp; this.handleChangeTenantId= this.handleChangeTenantId.bind(this);&nbsp; this.handleSubmit = this.handleSubmit.bind(this);};
打开App,查看更多内容
随时随地看视频慕课网APP