【问题标题】:Blazor.Client cannot see Blazor.Server on client startup and breakpoints not workingBlazor.Client 在客户端启动时看不到 Blazor.Server,断点不起作用
【发布时间】:2021-09-06 20:25:43
【问题描述】:

我创建了一个 Blazor 解决方案,它有一个 .client 项目和一个 .server 项目。

当我选择客户端作为启动时,它无法读取我在 .server 上的 api,当我选择 .server 作为启动时,它不会命中在我的 .client 中设置的断点。

我已尝试使用多启动项目设置,但它仍然无法读取服务器 API。

这是服务器应用程序中的启动设置,如果我在那里有检查 url,应用程序将无法启动并出现此错误

 "SeekaPortal.Server": {
  "commandName": "Project",
  "launchBrowser": true,
  "inspectUri": "{wsProtocol}://{url.hostname}:{url.port}/_framework/debug/ws-proxy?browser={browserInspectUri}",
  "environmentVariables": {
    "ASPNETCORE_ENVIRONMENT": "Development"
  },
  "applicationUrl": "https://localhost:5001;http://localhost:5000"
}

这是startup.cs

        public void ConfigureServices(IServiceCollection services) {


        services.AddMvc(options =>
        {
            options.EnableEndpointRouting = false;

        });
        
        services.AddDbContext<SeekaportalContext>(options =>
           options.UseSqlServer(Configuration.GetConnectionString("PortalConnection")));
        services.AddControllersWithViews();
        services.AddRazorPages();
        services.AddAuthentication();
        services.ConfigureIdentity();
        services.ConfigureJwt(Configuration);
        services.ConfigureServices();
        services.AddControllers();


    }

    // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
    public void Configure(IApplicationBuilder app, IWebHostEnvironment env) {
   

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

        app.UseHttpsRedirection();
        app.UseBlazorFrameworkFiles();
        app.UseStaticFiles();
        app.UseWebAssemblyDebugging();

        app.UseRouting();

        app.UseAuthentication();
        app.UseAuthorization();


        app.UseEndpoints(endpoints =>
        {
            endpoints.MapRazorPages();
            endpoints.MapControllers();
            endpoints.MapFallbackToFile("index.html");
        });


    }

如何让客户端读取服务器或在服务器启动时触发客户端应用程序上的断点?

非常感谢

【问题讨论】:

  • 只有在您的应用程序被托管时才必须启动服务器(创建应用程序时的 ASP.NET 托管复选框)。分享您的客户端在调试时不会停止的源代码。
  • 是的,它是 asp.net 托管的
  • 您必须将服务器设置为启动项目。它托管客户端,您也可以对其进行调试。如果您将客户端设置为启动项目,它将启动但不会启动服务器。如果单独启动服务器,安全性将不起作用。
  • 是的,我遇到的问题是它不允许我调试客户端。每个断点只是说“断点当前不会被命中。未绑定断点”
  • 请分享您的代码

标签: blazor blazor-server-side blazor-webassembly


【解决方案1】:

在客户端应用程序(webassembly)启动期间,调试器不应准备好附加到进程。在这种情况下,在 OnInitialized 等方法期间,您的断点a 未到达。

为了允许断点工作,您需要为异步方法添加 Task.Delayawait Task.Delay

只有在调试模式下才能使用条件来激活延迟,例如:

#if DEBUG
   Task.Delay(10000);
#endif

查看微软官方文档:
https://docs.microsoft.com/en-us/aspnet/core/blazor/debug?view=aspnetcore-5.0&tabs=visual-studio

【讨论】:

  • 即使这样也行不通,只是说断点不会被命中并且上面有警告符号
猜你喜欢
  • 1970-01-01
  • 2012-05-26
  • 1970-01-01
  • 2017-06-04
  • 1970-01-01
  • 1970-01-01
  • 2019-07-16
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多