【问题标题】:Redirect to HTTPS in Blazor在 Blazor 中重定向到 HTTPS
【发布时间】:2019-03-12 19:59:36
【问题描述】:

我有一个 Blazor 应用程序。 我将它托管在服务器上并可以使用 https 访问。 但是当我做重定向(在一个控制器中)时,会发生异常。

Startap.cs

public void Configure(IApplicationBuilder app, IHostingEnvironment env)
    {
        app.UseResponseCompression();

        if (env.IsDevelopment())
        {
            app.UseDeveloperExceptionPage();
        }

        app.UseHttpsRedirection();
        app.UseMvc(routes =>
        {
            routes.MapRoute(name: "default", template: "{controller}/{action}/{id?}");
        });

        app.Map("/schedule", subdirApp =>
        {
            subdirApp.UseBlazor<Client.Startup>();
        });
    }

控制器中的方法

[HttpGet]
[Route("***")]
public IActionResult Return()
{
   FileStream fs = new FileStream(_filePath, FileMode.Open);
   System.Runtime.Serialization.Formatters.Binary.BinaryFormatter formatter = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();
   List<ScheduleEntity> _list = (List<ScheduleEntity>)formatter.Deserialize(fs);
   foreach (var x in _list)
       Schedules.Add(x);
   fs.Close();
   return Redirect("~//schedule");
}

例外

请帮帮我

【问题讨论】:

    标签: asp.net-core blazor


    【解决方案1】:

    这些 API 响应可能有点误导。在没有看到您围绕端点配置的其余代码的情况下,我怀疑这可能是 API 的 CORS 问题。

    尝试将以下代码添加到 API 的 Startup.cs 类中的 public void Configure(IApplicationBuilder app, IHostingEnvironment env) 方法中:

            app.UseCors(opts => opts
                .AllowAnyOrigin()
                .AllowAnyMethod()
                .AllowAnyHeader()
                .AllowCredentials()
            );
    

    获取响应可能是由于请求预检被拒绝。

    话虽如此,第一条异常消息是说您正在尝试加载不安全的内容,所以我还要检查您的 Blazor 前端应用程序的配置以查看 API 客户端请求的内容并确保 API 端点证书是有效吗?

    【讨论】:

      猜你喜欢
      • 2020-03-24
      • 2011-08-18
      • 1970-01-01
      • 1970-01-01
      • 2016-05-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多