我在服务器端预渲染的 net6.0 应用程序上使用 HeadOutlet 来设置一些标头标签,例如元描述,但服务器首先渲染应用程序,然后渲染标头,这使得搜索引擎忽略它。
@page "/"
@namespace Example.Pages
@using Microsoft.AspNetCore.Components.Web
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
@{
Layout = null;
}
<!DOCTYPE html>
<html lang="en">
<head>
<component type="typeof(HeadOutlet)" render-mode="ServerPrerendered" />
<base href="~/" />
<link href="css/site.css" rel="stylesheet" />
<link rel="preconnect" href="https://fonts.gstatic.com">
</head>
<body>
<component type="typeof(App)" render-mode="ServerPrerendered" />
<div id="blazor-error-ui">
<environment include="Staging,Production">
An error has occurred. This application may no longer respond until reloaded.
</environment>
<environment include="Development">
An unhandled exception has occurred. See browser dev tools for details.
</environment>
<a href="/" class="reload">Reload</a>
<a href="#" …
Run Code Online (Sandbox Code Playgroud) I'm not sure what has changed but all of a sudden I get an "InvalidOperationException - Operation is not valid due to the current state of the object". My code has definitely worked previously and I can't remember changing anything.
I'm using Microsoft.Azure.ServiceBus 4.1.3
I tried some very basic code and still get the same error:
var bus = new QueueClient("Endpoint=sb://xxx.servicebus.windows.net/;SharedAccessKeyName=Manage;SharedAccessKey=xxx", "service-event");
await bus.SendAsync(new Message(Encoding.UTF8.GetBytes("{\"test\":\"hi\"}")));
Run Code Online (Sandbox Code Playgroud)
Any ideas?
Edit stacktrace:
at Microsoft.Azure.ServiceBus.Core.MessageSender.<OnSendAsync>d__58.MoveNext()
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at Microsoft.Azure.ServiceBus.RetryPolicy.<RunOperation>d__19.MoveNext()
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() …
Run Code Online (Sandbox Code Playgroud) 我正在尝试完成类似于下面的代码的事情,但我似乎无法弄清楚如何去做。
@page "/"
<div>@test</div>
@code {
[Parameter]
public string Animal { get; set; }
private BaseComponent test { get; set; }
protected override async Task OnInitializedAsync()
{
switch (Animal)
{
case "Cat": test = <Cat>Fluffy</Cat>; break;
case "Dog": test = <Dog>Woff</Dog>; break;
default: test = <p>None</p>
}
}
Run Code Online (Sandbox Code Playgroud)
我还希望能够将组件放入字典中 new Dictionary<string, BaseComponent> { {"cat", <Cat>test</Cat> }}
有任何想法吗?