首页 > 解决方案 > 我创建了一个带有 HttpGet 请求的 Blazor Web Assembly 应用程序,该应用程序在本地工作,但一旦发布到 Azure 就会失败

问题描述

我创建了一个带有 Httpget 请求的 Blazor Web 程序集应用程序。它在本地运行良好,但是当作为 ASP.NET 托管发布到 Azure 应用服务时,Httpget 请求失败并出现以下错误:

System.Text.Json.JsonReaderException:“<”是一个无效的值开始。行号:0 | BytePositionInLine: 0. 在 System.Text.Json.ThrowHelper.ThrowJsonReaderException (System.Text.Json.Utf8JsonReader& json, System.Text.Json.ExceptionResource 资源, System.Byte nextByte, System.ReadOnlySpan`1[T] 字节) <0x2a486d8 + 0x00020> in <515164c3ada14b86914aa92e915c4401>:0 at System.Text.Json.Utf8JsonReader.ConsumeValue (System.Byte marker) <0x2682800 + 0x00260> in <515164c3ada14b86914aa92e915c4401>:0 at System.Text.Json.Utf8JsonReader.ReadFirstToken (System.Byte第一个)<0x2681ad8 + 0x001ae> 在 <515164c3ada14b86914aa92e915c4401> 中:0 在 System.Text.Json.Utf8JsonReader.ReadSingleSegment () <0x26814d0 + 0x001fe> 在 <515164c3ada14b86914aa92e915>.c 中

// 在列表中创建我的数据

public class ConfiguratorRepo
{
        public List<Configurator> GetConfigurators()
        {
            Configurator Icfs = new Configurator
            {
                Name = "My test",
                ID = 99,
                Description = "Desc"
            };

            List<Configurator> Icf = new List<Configurator>
            {
                Icfs
            };

            return Icf;
        }
}

// 设置 HttpGet

[ApiController]
[Route("[controller]")]
public class ConfiguratorController : ControllerBase
{
    [HttpGet]
    [Route("GetAll")]
    public IList<Configurator> Get()
    {
        ConfiguratorRepo repo = new ConfiguratorRepo();

        return repo.GetConfigurators(); 
    }
}

//在我的 .razor 页面的代码部分中

    protected override async Task OnInitializedAsync()
    {
        try
        {
            Configurators = await Http.GetJsonAsync<List<Configurator>>("Configurator/GetAll");
        }
        catch (Exception e)
        {
            Error = e.InnerException.ToString();
        }

    }

这是项目的链接https://1drv.ms/u/s!As_wHGs2IYp0kgsfcf970zD53Vvt?e=mnPrph

有什么想法吗?

标签: azureblazor

解决方案


推荐阅读