在 JavaScript 中,我们可以使用以下调用将调试输出写入浏览器的控制台:
console.log("My debug output.");
Run Code Online (Sandbox Code Playgroud)
谷歌浏览器中的输出:
如何通过 Blazor WebAssembly 将组件中的“我的调试输出”记录到浏览器的控制台?
<button @onclick="ClickEvent">OK</button>
@code {
private void ClickEvent()
{
// console.log("My debug output.");
}
}
Run Code Online (Sandbox Code Playgroud) IIS-经理
要限制对Web应用程序的访问,管理员可以通过IIS管理器设置用户和组的URL授权:
Web.config文件
IIS-Manager将授权规则存储在应用程序的web.config中:
<security>
<authorization bypassLoginPages="true">
<remove users="*" roles="" verbs="" />
<add accessType="Allow" users="Testuser" />
<add accessType="Deny" users="*" />
</authorization>
</security>
Run Code Online (Sandbox Code Playgroud)
当bypassLoginPages设置为true,所有用户都有权访问登录页面.当用户未登录时,他将自动被重定向到登录页面:
<authentication mode="Forms">
<forms [...] loginUrl="~/Auth/Login" [...] >
[...]
</forms>
</authentication>
Run Code Online (Sandbox Code Playgroud)
MVC5应用程序:
用户必须通过Windows SamAccountName和密码通过自定义登录页面登录.凭据将发送到以下Login操作AuthController:
[AllowAnonymous]
public class AuthController : Controller
{
public ActionResult Login
{
// validation of SamAccountName and Password against Active Directory here.
[...]
// We want to check the authorization here.
// create authentication ticket
FormsAuthenticationTicket lFormsAuthenticationTicket …Run Code Online (Sandbox Code Playgroud) 我们使用 Wixtoolset V3.9 来构建我们的设置。我们使用以下命令来开始构建:
"C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\MSBuild\Current\Bin\msbuild.exe" /restore /t:Rebuild /p:Configuration=Release /p:Platform=x64 MySolution.sln /p:BabelEnabled=true
Run Code Online (Sandbox Code Playgroud)
我们需要该参数/restore来恢复构建服务器上的 nuget-packages。由于我们通过 MSBUILD 16 构建 Wix-Setup,我们收到以下警告:
Skipping restore for project 'SetupWix.wixproj'. The project file may be invalid or missing targets required for restore.
Run Code Online (Sandbox Code Playgroud)
该警告属于类别NU1503(无论这意味着什么)。我们找不到解决甚至抑制这个警告的方法。我们尝试通过将代码 NU1503 添加到项目属性来抑制它:
无论什么原因,警告仍然出现。
问题:我们如何解决或抑制这个警告?
我今天通过以下命令行安装了 Blazor WebAssembly 示例项目 (WeatherForecast):
dotnet new blazorwasm --hosted -o ProjectName
Run Code Online (Sandbox Code Playgroud)
我在调试模式下通过 Visual Studio 2019 安装后直接启动了 SPA。浏览器是:Chrome。浏览器显示应用程序,但是当我选择导航菜单“获取数据”时,什么也没有发生。Chrome 显示 1 个错误:
Microsoft.AspNetCore.Components.WebAssembly.Rendering.WebAssemblyRenderer[100]
Unhandled exception rendering component: The provided ContentType is not supported; the supported types are 'application/json' and the structured syntax suffix 'application/+json'.
System.NotSupportedException: The provided ContentType is not supported; the supported types are 'application/json' and the structured syntax suffix 'application/+json'.
at System.Net.Http.Json.HttpContentJsonExtensions.ValidateContent (System.Net.Http.HttpContent content) <0x2e87f38 + 0x0009a> in <filename unknown>:0
at System.Net.Http.Json.HttpContentJsonExtensions.ReadFromJsonAsync[T] (System.Net.Http.HttpContent content, System.Text.Json.JsonSerializerOptions options, System.Threading.CancellationToken cancellationToken) <0x2e87d30 + …Run Code Online (Sandbox Code Playgroud) asp.net asp.net-web-api blazor blazor-client-side blazor-webassembly
语境:
我们想要创建一个在客户端与 Blazor WebAssembly 一起运行的单页应用程序。在服务器端,该解决方案有一个 ASP.NET MVC,其中包括一些用于 REST API 的 ApiController 类。
我们希望在服务器端使用 ASP.NET API 而不是 Blazor Server,因为我们希望为未知消费者提供带有 ApiController 类的 REST 接口。
这是我在单个解决方案中的客户端 (Blazor WebAssembly) 和服务器端 (ASP.NET API) 项目:
第一次尝试通过我们的组件中的 Blazor 的 HttpClient 类请求 API FetchData:
@inject HttpClient Http
...
@code {
private TodoItem[] TodoItems;
protected override async Task OnInitializedAsync()
{
TodoItems = await Http.GetJsonAsync<TodoItem[]>("api/ToDo");
}
}
Run Code Online (Sandbox Code Playgroud)
在服务器端,API-Controller 看起来像:
namespace ToDoListAPI.Controllers
{
[Route("api/[controller]")]
[ApiController]
[Produces("application/json")]
public class ToDoController : ControllerBase
{
[HttpGet]
public string IGetAll()
{
var lResult = …Run Code Online (Sandbox Code Playgroud) asp.net-web-api single-page-application asp.net-core blazor asp.net-blazor
在我们的 Blazor WebAssembly 应用程序中,我们有一个ParentComponent嵌套多个ChildComponents. 有3个文件:
文件:测试.razor
<ParentComponent DataSource="@AccountList">
<ChildComponent TData="Account"><span>@context.FirstName</span></ChildComponent>
<ChildComponent TData="Account"><i>@context.LastName</i></ChildComponent>
<ChildComponent TData="Account"><b>@context.Age</b></ChildComponent>
</ParentComponent>
@code {
// The datasource:
private List<Account> AccountList = new List<Account>() {
new Account() { FirstName = "Sam", LastName = "Soldier", Age = 33},
new Account() { FirstName = "Lisa", LastName = "Johnson", Age = 25},
new Account() { FirstName = "Jonas", LastName = "Peer", Age = 50 } …Run Code Online (Sandbox Code Playgroud) 上下文:ASP.NET SignalR和ASP.NET Core SignalR之间有区别,您可以在此处阅读。
如本ASP.NET SignalR中的stackoverflow文章所述,您可以通过HubPipelineModuleASP.NET Core SignalR中不存在的异常在服务器端捕获未处理的异常。
我们如何捕获未处理的异常并将其传递给ASP.NET Core SignalR中的客户端?
JavaScript代码(客户端):
var hub = null;
var initWebSocket = function () {
hub = new signalR.HubConnectionBuilder().withUrl("/MyHub").build();
hub.on("ReceiveMessage", function (pMessage) {
[...]
});
hub.start().catch(function (err) {
return console.error(err.toString());
});
};
var executeWebsocketTestException = function () {
// send to server
hub.invoke("TestException").catch(function (exception) {
if(exception.type)
{
...
}
});
};
Run Code Online (Sandbox Code Playgroud)
ASP.NET Core 2集线器(服务器):
public class MyHub : Hub
{
public async Task TestException()
{
throw new …Run Code Online (Sandbox Code Playgroud) 在IIS管理器中,默认网站绑定在端口80上.如何使用c#按网站名称获取端口?我尝试了以下代码:
var lWebsite = "Default Web Site";
var lServerManager = new ServerManager();
var lPort = lServerManager.Sites[lWebsite].Bindings.GetAttributeValue("Port");
Run Code Online (Sandbox Code Playgroud)
lPort结果为null,但有invalid index异常.但是赋值变量lPort = lServerManager.Sites[lWebsite]有效.
我们有一个依赖于已安装的 .NET Framework 4.5 的应用程序。Wix 安装程序应自动检测何时未安装 .NET Framework 4.5(或更高版本)。这与以下 wix 声明配合得很好:
<PropertyRef Id="NETFRAMEWORK45"/>
<Condition Message=".NET Framwork 4.5 is not installed.">
<![CDATA[Installed OR NETFRAMEWORK45]]>
</Condition>
Run Code Online (Sandbox Code Playgroud)
我们的目标:Wix 安装程序应自动下载并安装 .Net Framework 4.5。看来“burn”提供了一种机制,让安装程序自动安装.NET Framwork:http://wixtoolset.org/documentation/manual/v3/howtos/redistributables_and_install_checks/install_dotnet.html。该文档定义了对 .NET Framework 安装文件的引用:
<MsiPackage Id="MyApplication" SourceFile="$(var.MyApplicationSetup.TargetPath)"/>
Run Code Online (Sandbox Code Playgroud)
但我们不想将 .NET Framework 添加到我们的安装程序中。安装程序应自动将其下载到将执行安装程序的目标系统上。
我们怎样才能做到这一点?