Asp.net core 提供了无效的请求URI。请求URI必须是绝对URI或必须设置基地址。在Blazor

Asp.net core 提供了无效的请求URI。请求URI必须是绝对URI或必须设置基地址。在Blazor,asp.net-core,asp.net-apicontroller,blazor-server-side,Asp.net Core,Asp.net Apicontroller,Blazor Server Side,点击控制器异常错误时出现“提供了无效的请求URI。请求URI必须是绝对URI或必须设置基地址。”****strong text blazor服务器端 控制器调用不在Razor组件中执行 视图代码 async Task UploadFile() { try { LoginRepository loginRepository = new LoginRepository(new LaborgDbContext()); DocumentService do

点击控制器异常错误时出现“提供了无效的请求URI。请求URI必须是绝对URI或必须设置基地址。”****strong text

blazor服务器端

控制器调用不在Razor组件中执行 视图代码

  async Task UploadFile()
  {
    try
    {
      LoginRepository loginRepository = new LoginRepository(new LaborgDbContext());
      DocumentService documentService = new DocumentService();
      var form = new MultipartFormDataContent();
      var content = new StreamContent(file.Data);
      content.Headers.ContentDisposition = new System.Net.Http.Headers.ContentDispositionHeaderValue("form-data")
      {
        Name = "files",
        FileName = file.Name
      };
      form.Add(content);
      var response = await HttpClient.PostAsync("/api/Document/Upload", form);    
    }
    catch (Exception ex)
    {
      throw ex;
    }

  }
控制器代码

[Route("api/[controller]/[action]")]
  [ApiController]
  public class UploadController : ControllerBase
  {
    private readonly IWebHostEnvironment _Env;

    public UploadController(IWebHostEnvironment env)
    {
      _Env = env;
    }
    [HttpPost()]
    public async Task<IActionResult> Post(List<IFormFile> files)
    {
      long size = files.Sum(f => f.Length);
      foreach (var formFile in files)
      {
        // full path to file in temp location
        var filePath = Path.GetTempFileName();
        if (formFile.Length > 0)
        {
          using (var stream = new FileStream(filePath, FileMode.Create))
          {
           await formFile.CopyToAsync(stream);
          }
        }

        System.IO.File.Copy(filePath, Path.Combine(_Env.ContentRootPath, "Uploaded", formFile.FileName)); 
      }

      return Ok(new { count = files.Count, size });
    }
{ 公共启动(IConfiguration配置) { 配置=配置; }

公共IConfiguration配置{get;}
//此方法由运行时调用。请使用此方法将服务添加到容器中。
//有关如何配置应用程序的更多信息,请访问https://go.microsoft.com/fwlink/?LinkID=398940
public void配置服务(IServiceCollection服务)
{
services.AddAuthorizationCore();
services.AddDbContext(选项=>
options.UseSqlServer(
GetConnectionString(“DefaultConnection”);
services.AddDefaultIdentity()
.AddEntityFrameworkStores();
services.AddRazorPages();
AddServerSideBlazor();
services.addScope();
services.AddSingleton();
services.AddSingleton();
services.AddSingleton();
services.AddSingleton();
services.AddFileReaderService(options=>options.InitializeOnFirstCall=true);
services.AddSingleton();
服务
.AddBlazorise(选项=>
{
options.ChangeTextOnKeyPress=true;//可选
})
.AddBootstrapProviders()
.AddFontAwesomeIcons();
}
public void配置(IApplicationBuilder应用程序、IWebHostEnvironment环境)
{
if(env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
app.UseDatabaseErrorPage();
}
其他的
{
app.UseExceptionHandler(“/Error”);
app.UseHsts();
}
app.UseHttpsRedirection();
app.UseStaticFiles();
app.UseRouting();
应用程序UseMbeddedBlazorContent(类型为(MatBlazor.BaseMatComponent).Assembly);
app.useMbeddedBlazorContent(typeof(BlazorDateRangePicker.DateRangePicker.Assembly);
app.UseAuthentication();
app.UseAuthorization();
app.UseEndpoints(端点=>
{
endpoints.MapControllers();
endpoints.MapBlazorHub();
endpoints.MapFallbackToPage(“/_主机”);
});
}
}
}startup.cs页,并将以下代码添加到app.UseEndpoints方法的末尾(在endpoints.MapFallbackToPage(“/_Host”);行下),以允许正确路由到控制器的http请求

添加以下行 endpoints.MapControllerRoute(“默认值”,“{controller=Home}/{action=Index}/{id?}”)

app.UseEndpoints(endpoints =>
      {
        endpoints.MapBlazorHub();
        endpoints.MapFallbackToPage("/_Host");
        endpoints.MapControllerRoute("default", "{controller=Home}/{action=Index}/{id?}");
      });

当位置包含
%20

发件人:@


我们已将此问题移至积压工作里程碑。这意味着在即将发布的版本中不会对其进行处理。我们将重新评估当前发布后的积压并考虑这个项目。

请显示您的<代码>启动。CS 代码包括Stututu.CsI有相同的问题。除了单机,我的启动页面是相同的。但是,当我尝试调用HTTP.PASJSONASYNC时,我得到了同样的错误信息-还有其他的想法吗?我已经使用VS2019创建了一个新的服务器端blazor应用程序
public IConfiguration Configuration { get; }

// This method gets called by the runtime. Use this method to add services to the container.
// For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940
public void ConfigureServices(IServiceCollection services)
{
  services.AddAuthorizationCore();
  services.AddDbContext<ApplicationDbContext>(options =>
      options.UseSqlServer(
          Configuration.GetConnectionString("DefaultConnection")));
  services.AddDefaultIdentity<IdentityUser>()
      .AddEntityFrameworkStores<ApplicationDbContext>();
  services.AddRazorPages();
  services.AddServerSideBlazor();
  services.AddScoped<AuthenticationStateProvider, RevalidatingIdentityAuthenticationStateProvider<IdentityUser>>();
  services.AddSingleton<WeatherForecastService>();
  services.AddSingleton<TaskSchedulerService>();
  services.AddSingleton<TimeOffSchedulerService>();
  services.AddSingleton<DocumentService>();
  services.AddFileReaderService(options => options.InitializeOnFirstCall = true);
  services.AddSingleton<HttpClient>();

  services
.AddBlazorise(options =>
{
  options.ChangeTextOnKeyPress = true; // optional
})
.AddBootstrapProviders()
.AddFontAwesomeIcons();
}


public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
  if (env.IsDevelopment())
  {
    app.UseDeveloperExceptionPage();
    app.UseDatabaseErrorPage();
  }
  else
  {
    app.UseExceptionHandler("/Error");

    app.UseHsts();
  }

  app.UseHttpsRedirection();
  app.UseStaticFiles();

  app.UseRouting();
  app.UseEmbeddedBlazorContent(typeof(MatBlazor.BaseMatComponent).Assembly);
  app.UseEmbeddedBlazorContent(typeof(BlazorDateRangePicker.DateRangePicker).Assembly);
  app.UseAuthentication();
  app.UseAuthorization();

  app.UseEndpoints(endpoints =>
  {
    endpoints.MapControllers();
    endpoints.MapBlazorHub();
    endpoints.MapFallbackToPage("/_Host");
  });
}
app.UseEndpoints(endpoints =>
      {
        endpoints.MapBlazorHub();
        endpoints.MapFallbackToPage("/_Host");
        endpoints.MapControllerRoute("default", "{controller=Home}/{action=Index}/{id?}");
      });