我正在开发一个 API ASP.Net Core (net6.0),其中通过请求在请求标头中传递密钥 (X-API-KEY) 和应用程序 id (X-APP-ID) 来实现身份验证。
https://swagger.io/docs/specification/authentication/api-keys/的“多个 API 密钥”部分对此进行了描述
我在 Program.cs 中配置此功能的代码可以在下面找到。
builder.Services.AddSwaggerGen(c =>
{
c.AddSecurityDefinition("apiKey", new OpenApiSecurityScheme()
{
Description = "API KEY",
Name = "X-API-KEY",
In = ParameterLocation.Header,
Type = SecuritySchemeType.ApiKey
});
c.AddSecurityDefinition("appId", new OpenApiSecurityScheme()
{
Description = "APP ID",
Name = "X-APP-ID",
In = ParameterLocation.Header,
Type = SecuritySchemeType.ApiKey
});
c.AddSecurityRequirement(new OpenApiSecurityRequirement()
{
{
new OpenApiSecurityScheme
{
Reference = new OpenApiReference
{
Type = ReferenceType.SecurityScheme,
Id = "apiKey"
}
},
Array.Empty<string>()
},
{
new …Run Code Online (Sandbox Code Playgroud) asp.net-web-api swagger-ui asp.net-core openapi swashbuckle.aspnetcore
我已经接管了网站的维护(ASP.NET VB),在一个特定的页面上,我注意到了下面的代码
Inherits System.Web.UI.Page
Public Shared UserNumber As String
Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
UserNumber = Session("UserNumber")
...
End Sub
Run Code Online (Sandbox Code Playgroud)
我的问题是变量UserNumber是否可以由当前用户以外的任何其他用户访问或更改?
非常感谢
我正在尝试实现https://learn.microsoft.com/en-us/aspnet/core/blazor/forms-validation?view=aspnetcore-3.1#work-with-radio中找到的“使用单选按钮”示例-buttons然而,当我尝试将它与枚举一起使用时遇到了困难。
@page "/RadioButtonExample"
@using System.ComponentModel.DataAnnotations
@using MyApp.Shared
<h1>Radio Button Group Test</h1>
<EditForm Model="model" OnValidSubmit="HandleValidSubmit">
<DataAnnotationsValidator />
<ValidationSummary />
@foreach (int status in Enum.GetValues(typeof(Status)))
{
<label>
<InputRadio name="rate" SelectedValue="status" @bind-Value="model.Status" />
@status
</label>
}
<button type="submit">Submit</button>
</EditForm>
<p>You chose: @model.Status</p>
@code {
private Administrator model = new Administrator();
private void HandleValidSubmit()
{
Console.WriteLine("valid");
}
}
Run Code Online (Sandbox Code Playgroud)
我的枚举定义如下
public enum Status
{
Disabled = 0,
Enabled = 1
}
Run Code Online (Sandbox Code Playgroud)
我收到的错误如下,我明白为什么会出现这种情况,但是,我不确定如何最好地解决。
TypeInference.CreateInputRadio_0(RenderTreeBuilder, int, int, object, int, TValue, int, TValue, int, EventCallback, int, …
我正在尝试将 datatables.net 与我的服务器端 Blazor 应用程序一起使用,任何帮助将不胜感激。
我已经尝试了中途提到的代码https://datatables.net/forums/discussion/56389/datatables-with-blazor,但是,我遇到的问题是正在复制某些 UI 元素,例如分页当我在页面之间浏览时。
下面是我的 _Host.cshtml 文件
@page "/"
@namespace MyApplication.Web.Pages
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
@{
Layout = null;
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>MyApplication.Web</title>
<base href="~/" />
<link rel="stylesheet" href="css/bootstrap/bootstrap.min.css" />
<link href="css/site.css" rel="stylesheet" />
<script src="/lib/jquery/jquery.min.js"></script>
<script src="/lib/datatables/js/jquery.dataTables.min.js"></script>
<link href="/lib/datatables/css/jquery.dataTables.min.css" rel="stylesheet" />
</head>
<body>
<app>
<component type="typeof(App)" render-mode="ServerPrerendered" />
</app>
<div id="blazor-error-ui">
<environment include="Staging,Production">
An error has occurred. This application may no longer respond …Run Code Online (Sandbox Code Playgroud) 我正在开发服务器端 Blazor 应用程序,并且在返回以下 JSON 的特定 API 调用时遇到问题。
{
"id": 2,
"status": 1,
"fileName": "Test PDF",
"fileType": "PDF",
"fileBytes": "",
"allSchemes": false,
"dateModified": "2020-06-12T12:32:08.99",
"dateCreated": "2020-06-11T11:32:19.877",
"isNew": false,
"schemes": [
{
"schemeCode": "0185",
"schemeName": null,
"baseCurrency": null
},
{
"schemeCode": "0186",
"schemeName": null,
"baseCurrency": null
}
]
}
Run Code Online (Sandbox Code Playgroud)
但是,当我使用下面的代码反序列化时,方案列表始终为 0。其他详细信息按预期填充
var accessToken = await _apiService.RequestNewToken(_httpClient);
_httpClient.SetBearerToken(accessToken);
return await JsonSerializer.DeserializeAsync<SchemeDocument>
(await _httpClient.GetStreamAsync($"api/schemeDocument/{id}"), new JsonSerializerOptions { PropertyNameCaseInsensitive = true });
Run Code Online (Sandbox Code Playgroud)
SchemeDocument 类是
public class SchemeDocument
{
public int Id { get; set; } …Run Code Online (Sandbox Code Playgroud) 我正在开发一个服务器端 Blazor 应用程序,该应用程序是使用为身份验证选择的“个人用户帐户”选项创建的。
我现在想自定义登录页面,但是当我选择通过脚手架添加身份页面时,我收到以下错误,我不知道从哪里开始进行故障排除。
无法在内存中编译项目
.OnInitializedAynsc() 找不到合适的方法来覆盖
为我的项目中的每个页面列出了上述错误。