相关文章推荐
精明的椅子  ·  免高考!福建这106名学生拟保送清华北大等名 ...·  1 年前    · 
沉稳的电梯  ·  瑟姆议会,施拉赤塔和第四、五次莫-立战争—— ...·  1 年前    · 
发财的乌龙茶  ·  沙拉:被中国母亲抛弃,犹太父亲抚养长大,自己 ...·  2 年前    · 
谦逊的石榴  ·  《鱿鱼游戏》抄袭了那几部高智商暗黑漫画? - 知乎·  2 年前    · 
Code  ›  提供了一个无效的请求URI。请求URI必须是绝对URI,或者必须设置BaseAddress。在巴兹尔开发者社区
uri app services
https://cloud.tencent.com/developer/ask/sof/108480241
咆哮的黑框眼镜
2 年前
首页
学习
活动
专区
工具
TVP 最新优惠活动
返回腾讯云官网
提问

问 提供了一个无效的请求URI。请求URI必须是绝对URI,或者必须设置BaseAddress。在巴兹尔

Stack Overflow用户
提问于 2019-10-10 06:31:12
EN

当 碰到控制器异常错误时,“提供了无效的请求URI。请求URI必须是绝对URI,或者必须设置BaseAddress。”*强文本 。

blazor服务器端

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

  async Task UploadFile()
      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 });
    }

启动

  public class Startup

{公共启动(IConfiguration配置){ Configuration = configuration;}

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();
    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");
 
推荐文章
精明的椅子  ·  免高考!福建这106名学生拟保送清华北大等名校!_腾讯新闻
1 年前
沉稳的电梯  ·  瑟姆议会,施拉赤塔和第四、五次莫-立战争——正说波兰史(十二) | 机核 GCORES
1 年前
发财的乌龙茶  ·  沙拉:被中国母亲抛弃,犹太父亲抚养长大,自己生下亿万富豪|犹太人|特别狠心特别爱|莎拉_网易订阅
2 年前
谦逊的石榴  ·  《鱿鱼游戏》抄袭了那几部高智商暗黑漫画? - 知乎
2 年前
今天看啥   ·   Py中国   ·   codingpro   ·   小百科   ·   link之家   ·   卧龙AI搜索
删除内容请联系邮箱 2879853325@qq.com
Code - 代码工具平台
© 2024 ~ 沪ICP备11025650号