在 blazor 应用程序上工作,它有一个需要从 JS 调用的方法!当我尝试调用没有 static 关键字的方法时,出现此错误 -
The assembly 'AssemblyName' does not contain a public invokable method with [JSInvokableAttribute("INIT_COMPLIANCE")].
Run Code Online (Sandbox Code Playgroud)
一旦我添加静态,它就会识别并加载它。
这是我在 blazor 组件中的代码 -
protected override Task OnInitializedAsync()
{
jsToDotNetBridgeReference = DotNetObjectReference.Create(this);
js.InvokeVoidAsync("SetDotNetReference", jsToDotNetBridgeReference);
return base.OnInitializedAsync();
}
[JSInvokableAttribute("INIT_COMPLIANCE")]
public async void InitComplianceComponent(string token)
{
id_token = token;
Console.WriteLine(token);
await GetData();
}
Run Code Online (Sandbox Code Playgroud)
JS-
self.addNewCompliance = function () {
const url = someurl;
var resource = window.authContext.getResourceForEndpoint(url);
window.authContext.acquireToken(resource, function (error, token) {
// Handle ADAL Error
if (error || !token) { …Run Code Online (Sandbox Code Playgroud) 我在 Blazor 中使用自定义验证,验证执行正确,但是当它无效时,不会显示ValidationMessage For ,我尝试添加 ValidationSummary,但这里确实出现 ErrorMessage。我希望有人能支持我
\n\n public class Domicilio\n {\n public int Id { get; set; }\n public DateTimeOffset FechaRegistro { get; set; }\n [Required(ErrorMessage ="Favor de capturar la calle")]\n public string Calle { get; set; }\n [Required(ErrorMessage = "Favor de capturar el n\xc3\xbamero exterior")]\n public string NumeroExt { get; set; }\n public string NumeroInt { get; set; }\n [Range(1,int.MaxValue, ErrorMessage="Favor de seleccionar la colonia")]\n public int CodigoPostalId { get; set; }\n public CatCodigosPostales CodigoPostal …Run Code Online (Sandbox Code Playgroud) 我正在尝试发布我的 blazor wasm 项目。当我点击托管它的 url 时,该应用程序永远不会加载,并且我在控制台中看到此错误:
Error: Failed to start platform. Reason: TypeError: NetworkError when attempting to fetch resource.
g https://my-test-server.com/_framework/blazor.webassembly.js:1
s https://my-test-server.com/_framework/blazor.webassembly.js:1
s https://my-test-server.com/_framework/blazor.webassembly.js:1
s https://my-test-server.com/_framework/blazor.webassembly.js:1
promise callback*u https://my-test-server.com/_framework/blazor.webassembly.js:1
a https://my-test-server.com/_framework/blazor.webassembly.js:1
promise callback*u https://my-test-server.com/_framework/blazor.webassembly.js:1
a https://my-test-server.com/_framework/blazor.webassembly.js:1
promise callback*u https://my-test-server.com/_framework/blazor.webassembly.js:1
r https://my-test-server.com/_framework/blazor.webassembly.js:1
r https://my-test-server.com/_framework/blazor.webassembly.js:1
g https://my-test-server.com/_framework/blazor.webassembly.js:1
<anonymous> https://my-test-server.com/_framework/blazor.webassembly.js:1
n https://my-test-server.com/_framework/blazor.webassembly.js:1
<anonymous> https://my-test-server.com/_framework/blazor.webassembly.js:1
<anonymous> https://my-test-server.com/_framework/blazor.webassembly.js:1
blazor.webassembly.js:1:14889
printErr https://my-test-server.com/_framework/blazor.webassembly.js:1
<anonymous> https://my-test-server.com/_framework/blazor.webassembly.js:1
(Async: promise callback)
<anonymous> https://my-test-server.com/_framework/blazor.webassembly.js:1
n https://my-test-server.com/_framework/blazor.webassembly.js:1
<anonymous> https://my-test-server.com/_framework/blazor.webassembly.js:1
<anonymous> https://my-test-server.com/_framework/blazor.webassembly.js:1
Run Code Online (Sandbox Code Playgroud)
这个错误并没有给我太多继续下去的机会...任何人都知道我可以从哪里开始寻找以试图弄清楚发生了什么?
在我的 .Net CORE 5(导入的支持文件 v5.0.12)Blazor PWA VS-2019 解决方案中,我“拥有”一个工作的“客户”-(数据/应用程序)服务和 Blazor 页面来列出和 CRUD 客户记录(工作原理为预期的)。我为服务器项目和客户端项目创建了类似的“车辆”文件(当然更改了模型字段引用)。
目前还没有编译错误,当我尝试显示“VehicleList”页面时,此错误出现在输出窗口中:
crit: Microsoft.AspNetCore.Components.WebAssembly.Rendering.WebAssemblyRenderer[100] 未处理的异常渲染组件:无法为类型 'MyCore5AppPWA.Client.Pages.VehicleList'上的属性'_vehicleService'提供值。没有类型为'MyCore5AppPWA.Client.Services.IVehicleService'的已注册服务。System.InvalidOperationException:无法为类型'MyCore5AppPWA.Client.Pages.VehicleList'上的属性'_vehicleService'提供值 。 没有类型为'MyCore5AppPWA.Client.Services.IVehicleService'的已注册服务。在 Microsoft.AspNetCore.Components.ComponentFactory.<> c__DisplayClass6_0 .g__Initialize|2(IServiceProvider serviceProvider,IComponent 组件)
请注意上面的“...c__DisplayClass6_0...”符号,这对我来说很好奇(不知道其意义)。我已经阅读了许多与本文主题相关的类似问题/答案,但这些问题/答案并未纠正错误。
以下是 Startup.cs 文件中的片段:
public void ConfigureServices(IServiceCollection services) {
_ = services.AddDbContext<AppDbContext>(options => options.UseSqlServer(Configuration.GetConnectionString("DbConnection")));
services.AddScoped<ICustomerRepository, CustomerRepository>();
services.AddScoped<IVehicleRepository, VehicleRepository>();
services.AddControllersWithViews();
services.AddRazorPages();
services.AddScoped<WeatherForecastService>();
}
Run Code Online (Sandbox Code Playgroud)
以下是“VehicleList.razor”代码文件中的片段。
//html... declarations.
@layout MainLayout
@page "/vehiclelist"
@using MyCore5AppPWA.Client.Services;
@using MyCore5AppPWA.Shared
//...html omitted...//
@code {
[Inject]
private IVehicleService _vehicleService { get; set; …Run Code Online (Sandbox Code Playgroud) 我在这件事上浪费了很多天,希望能得到一些指导,即使是在不同的网站上发布。
我正在使用 VS 2022 开发 Blazor Web Assembly 应用程序。大约一周前,我的调试器开始不再在客户端应用程序中的断点处停止。它确实停止在服务器应用程序上。
在这个问题开始的同时,我注意到当我启动调试会话时,它开始在 Edge 中打开一个新选项卡而不是一个新窗口;不确定这是否相关。
几点:
一直在寻找并找到一些可以尝试的小东西,但没有任何效果。
我想不出我对环境等做了什么改变。
希望得到某种指导。
debugging breakpoints blazor blazor-webassembly visual-studio-2022
我正在开发一个 Blazor 项目,并尝试将其中一个 JavaScript 文件移动到类库,我已阅读以下指南:
我收到以下错误:
我不确定我缺少什么或者我需要做什么才能让它工作,所以这是我的设置:
事实:
.NET 6。Version 17.0 Preview (17.0 build 8754)。LinkScreen。Client.Web。LinkScreen.Client.Web。LinkScreen.Client.Web。Client.BrowserInterop。LinkScreen.Client.BrowserInterop。LinkScreen.Client.BrowserInterop。项目结构及代码
screen-capture.js在以下目录下调用的脚本文件wwwroot\scripts,如下所示:其构建操作设置为“内容”,并将复制到输出目录设置为“不复制”。
ScreenCapture,它包装了 JavaScript 模块,screen-capture.js并返回引用,如下所示:public static async ValueTask<ScreenCapture> CreateAsync(
IJSRuntime jsRuntime,
ElementReference videoTagReference)
{
var jsModuleRef …Run Code Online (Sandbox Code Playgroud) 所以我一直在 Net7 预览版中工作,并一直在尝试部署一个具有身份和身份验证功能的 WASM 项目,该项目在本地运行良好。当我部署网站 500 秒并深入研究一些日志时,我得到:
2022-11-07T13:42:28.854805951Z fail: Microsoft.AspNetCore.Authentication.JwtBearer.JwtBearerHandler[3]
2022-11-07T13:42:28.854856853Z Exception occurred while processing message.
2022-11-07T13:42:28.854865053Z System.NullReferenceException: Object reference not set to an instance of an object.
2022-11-07T13:42:28.856255318Z at Microsoft.AspNetCore.ApiAuthorization.IdentityServer.IdentityServerJwtBearerOptionsConfiguration.ResolveAuthorityAndKeysAsync(MessageReceivedContext messageReceivedContext)
2022-11-07T13:42:28.856286120Z at Microsoft.AspNetCore.Authentication.JwtBearer.JwtBearerHandler.HandleAuthenticateAsync()
Run Code Online (Sandbox Code Playgroud)
在我的 Program.cs 中我有
builder.Services.AddDbContext<ApplicationDbContext>(options =>
options.UseSqlServer(connectionString));
builder.Services.AddDatabaseDeveloperPageExceptionFilter();
builder.Services.AddDefaultIdentity<ApplicationUser>(options => options.SignIn.RequireConfirmedAccount = true)
.AddEntityFrameworkStores<ApplicationDbContext>();
builder.Services.AddIdentityServer()
.AddApiAuthorization<ApplicationUser, ApplicationDbContext>();
builder.Services.AddAuthentication()
.AddIdentityServerJwt()
.AddJwtBearer()
.AddGoogle(googleOptions =>
{
googleOptions.ClientId = builder.Configuration["Authentication:Google:ClientId"];
googleOptions.ClientSecret = builder.Configuration["Authentication:Google:ClientSecret"];
});
builder.Services.AddControllersWithViews();
builder.Services.AddRazorPages();
builder.Services.AddHttpContextAccessor();
var app = builder.Build();
// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{ …Run Code Online (Sandbox Code Playgroud) identity azure blazor-webassembly duende-identity-server .net-7.0
我从 Blazor 静态 Web 应用程序调用“/.auth/login/google”(或其他提供商)。一旦用户同意,控制权将被路由回索引页面。有没有办法指定我想要不同的返回页面,例如通过“/.auth/login/google?callback=http...”之类的内容?
openid-connect azure-web-app-service blazor blazor-webassembly azure-static-web-app
如何在 Blazor 页面上清晰地显示 JSON 格式?
parsedResult目前我在文本区域中显示 JSON ( ):
<div class="col-lg-12 noSidePadding" id="parser" data-bind="visible: ParserVisible">
<h3>Parser</h3>
<div>
<EditForm Model=@TLogMessageRequestDto>
<div class="form-group">
<label for="lblMessage">Message:</label>
<textarea class="form-control textAreaSize" id="source" @bind="inputMessage" rows="5"></textarea>
<input type="submit" id="upload" class="btn btn-primary" @onclick="OnParseClicked" value="Parse"/>
</div>
</EditForm>
</div>
<br />
<div>
<label for="results">Results:</label><br />
<textarea id="results" @bind="parsedResult"></textarea>
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
输出:
我有一个令人兴奋的 NavMenu 组件
<MudPaper Class="py-3" Elevation="0">
<MudNavMenu>
<MudNavLink Href="/" Match="NavLinkMatch.All">Home</MudNavLink>
<MudNavLink Href="/posts" Match="NavLinkMatch.All">Articles</MudNavLink>
<MudNavLink Href="/about" Match="NavLinkMatch.All">About</MudNavLink>
</MudNavMenu>
</MudPaper>
<MudSwitch @ref="@darkModeSwitch" *@ ... @* />
Run Code Online (Sandbox Code Playgroud)
那是在 a 里面MudDrawer。我真正想要的是将所有 NavLink 放在顶部,将开关放在底部,但我尝试过的所有操作似乎都没有效果。看起来该MudDrawer组件是在列表中一个接一个的事物上设置的。我缺少什么?或者有什么快速解决办法吗?
大多数情况下,我尝试在开关周围放置一个容器并为其提供顶部边距,并使用对齐和调整弹性类。
blazor ×7
c# ×3
asp.net-core ×2
.net ×1
.net-7.0 ×1
azure ×1
breakpoints ×1
debugging ×1
html ×1
identity ×1
javascript ×1
mudblazor ×1