在处理我面临的问题的程序时,构造函数及其子类的依赖注入。
constructor(private url: string, private http: Http) { }
Run Code Online (Sandbox Code Playgroud)
constructor(http: Http) {
super('https://jsonplaceholder.typicode.com/posts', http);
}
Run Code Online (Sandbox Code Playgroud)
在此重构之前(移动所有常见的 CRUD 操作并通过子类扩展它),我的代码按预期工作,但在进行上述更改后,我收到以下错误:
Date: 2020-03-22T15:26:23.248Z - Hash: 7130497a38c152c58258
5 unchanged chunks
Time: 1859ms
ERROR in src/app/services/data.service.ts:14:23 - error NG2003: No suitable injection token for parameter 'url' of class 'DataService'.
Found string
14 constructor(private url: string, private http: Http) { }
Run Code Online (Sandbox Code Playgroud)
此外,当我从 Datsource 构造函数中删除url参数(相应地修改 PostService.ts)时,api 按预期工作。 …
因此,我尝试使用 ASP.NET Core 3.1 实现 OIDC 客户端应用程序。我正在尝试利用.AddOpenIdConnect()
和.AddJswtBearer()
中间件。但是,我需要澄清一下这个中间件的作用。
这是我目前的中间件配置:
.AddOpenIdConnect(options =>
{
options.Authority = Configuration["auth:oidc:authority"];
options.ClientId = Configuration["auth:oidc:clientid"];
options.ClientSecret = Configuration["auth:oidc:clientsecret"];
options.ResponseType = OpenIdConnectResponseType.Code;
options.GetClaimsFromUserInfoEndpoint = true;
options.SaveTokens = true;
})
.AddJwtBearer(options =>
{
options.Authority = Configuration["auth:oidc:authority"];
options.Audience = Configuration["auth:oidc:clientid"];
options.TokenValidationParameters = new TokenValidationParameters
{
ValidateIssuer = true,
ValidateAudience = true,
ValidateLifetime = true,
ValidIssuer = Configuration["auth:oidc:authority"],
ValidAudience = Configuration["auth:oidc:clientid"],
ValidateIssuerSigningKey = true,
ClockSkew = TimeSpan.Zero
};
}
Run Code Online (Sandbox Code Playgroud)
我注意到,根据下面的 Fiddler 捕获,应用程序首次启动时会请求对授权服务器/.well-known/oidc-configuration
和端点的请求/.well-known/keys
它在哪里做到这一点?
我还尝试验证从授权服务器收到的 JWT …
我有一个带有表单和多个提交按钮的剃刀页面。对于每个按钮,我想在代码隐藏文件中启动不同的 Post 操作。这是我的 cshtml 页面:
\n<form class="form" method="post" >\n <input type="submit" value="Test1" formaction="Button1" />\n <input type="submit" value="Test2" formaction="Button2" />\n</form>\n
Run Code Online (Sandbox Code Playgroud)\n这在我的 cshtml.cs 文件中:
\n[HttpPost]\npublic IActionResult Button1(IFormCollection data)\n{\n//my code\n}\n\n[HttpPost]\npublic IActionResult Button2(IFormCollection data)\n{\n//my code\n}\n
Run Code Online (Sandbox Code Playgroud)\n不幸的是,这不起作用。当我提交时出现 404 错误:
\n无法找到此 localhost 页面\xe2\x80\x99 找不到该网址的网页:https://localhost:44366/Mutations/Button1\nHTTP ERROR 404
\n正确的 URL 应该是:https://localhost:44366/Mutations/Test
\n我究竟做错了什么?
\n我需要一个登录的帖子请求。我正在 WPF 中使用 webview2 包并使用它。
我的代码是这样的:
HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Post, new Uri("Sample_url"));
request.Content = new FormUrlEncodedContent(new[] {
new KeyValuePair<string, string>("email", email),
new KeyValuePair<string, string>("password", "123"),
});
// webview2 does not contain a defenition for 'NavigateWithHttpRequestMessage'
Browser.NavigateWithHttpRequestMessage();
Run Code Online (Sandbox Code Playgroud)
我想做的是先登录用户,然后向他展示视图。
有什么方法可以向操作系统发送多媒体控制命令,例如下一首歌曲、暂停、播放、音量增大等?按Fn+ 一些映射时发送的命令..key。我正在为 PC 制作遥控器,发送这些命令是必不可少的。
我试图弄清楚如何实现setDisabledState
作为接口一部分的函数ControlValueAccessor
,但我无法弄清楚如何从组件本身的外部实际触发该函数。
在我有的组件内
control = new FormControl();
setDisabledState(isDisabled: boolean): void {
this._renderer.setProperty(this.formField.nativeElement, 'disabled', isDisabled);
}
Run Code Online (Sandbox Code Playgroud)
如果我在组件的 NgOnInit 中执行以下操作,这会将我的禁用样式设置得很好。但我希望能够通过属性绑定来控制组件的禁用状态。
this.tenantListFormControl.disable();
Run Code Online (Sandbox Code Playgroud)
然而,实际上没有任何东西触发该函数。
我试过了
<app-custom-control [attr.disabled]="true"></app-custom-control>
<app-custom-control disabled></app-custom-control>
<app-custom-control [disabled]="true"></app-custom-control>
Run Code Online (Sandbox Code Playgroud)
最后一个甚至无效,因为“任何适用的指令等均未提供禁用的属性...”,因为我没有@Input()
在组件上的任何位置禁用。无论如何这都没有帮助,因为一旦我设置了它,我应该如何处理它,我无法订阅它并以这种方式触发 setDisabledState 函数,因为它不是可观察的。
我如何实际触发此功能并禁用我的组件?
我不确定我是否完全理解 Microsoft.Identity.Web 的更改,但我正在关注一篇文章(由 Microsoft 提供),其中描述了如何在启动时进行更改
services.AddAuthentication(AzureADDefaults.AuthenticationScheme)
.AddAzureAD(options => Configuration.Bind("AzureAd", options));
Run Code Online (Sandbox Code Playgroud)
到
services.AddMicrosoftIdentityWebAppAuthentication(Configuration);
Run Code Online (Sandbox Code Playgroud)
虽然这看起来很好很简单,但我还有更多工作要做,因为我现有的代码中有以下代码片段
services.AddAuthentication(AzureADDefaults.AuthenticationScheme)
.AddAzureAD(options => this.configuration.Bind("AzureAd", options))
.AddJwtBearer(options =>
{
//this code used to validate signing keys
string stsDiscoveryEndpoint = "https://login.microsoftonline.com/common/v2.0/.well-known/openid-configuration";
IConfigurationManager<OpenIdConnectConfiguration> configurationManager = new ConfigurationManager<OpenIdConnectConfiguration>(stsDiscoveryEndpoint, new OpenIdConnectConfigurationRetriever());
OpenIdConnectConfiguration openIdConfig = configurationManager.GetConfigurationAsync(CancellationToken.None).GetAwaiter().GetResult();
var tenantId = this.configuration["TenantId"];
var validIssuer = $"https://sts.windows.net/{tenantId}/";
options.TokenValidationParameters = new TokenValidationParameters()
{
ValidIssuer = validIssuer,
ValidAudience = this.configuration["ClientId"],
IssuerSigningKeys = openIdConfig.SigningKeys,
};
});
Run Code Online (Sandbox Code Playgroud)
为了给您提供一些背景信息,我们对该应用程序有两种变体
您在上面看到的 JWTvaliation 部分适用于第二项,一旦我们收到令牌,我们就会在无需登录和 UI …
c# asp.net-core microsoft-identity-platform asp.net-core-3.1
我们正在将现有的 REST API 服务转换为 gRPC 核心。在迁移现有类时,我们知道 gRPC 没有十进制数据类型。我们在 C# 中有一个类,其定义为
public class SalarySchedule
{
public decimal Salary { get; set; }
public DateTime? SalaryDate { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
我们在 proto 文件中将其实现为
message SalarySchedule
{
// TODO: How to define this double to decimal
double Salary = 1;
google.protobuf.Timestamp SalaryDate =2;
}
Run Code Online (Sandbox Code Playgroud)
目前,我们使用double作为Salary数据类型。但这导致内部计算出现问题。
您能否指导我们,我们如何将其定义为gRPC 中的小数?
在我们项目中的某些情况下,我们必须忽略当前的应用程序文化并获取英语资源。
基本上,我们对所有语言都这样做
<label>@ModelEntities.Properties.Resource.Gender</label>
Run Code Online (Sandbox Code Playgroud)
怎么可能只用英语?
我假设我们以某种方式创建了一些对Resource.resx
?
我用过了
ResourceManager rm = new ResourceManager("Resource.Strings",
Assembly.GetAssembly(typeof(ModelEntities.Properties.Resource)));
var s = rm.GetString("Age");
Run Code Online (Sandbox Code Playgroud)
但它似乎不起作用。
谢谢!
我有一个自定义结构,代码如下:
[Serializable]
public struct HexPoint : IEquatable<HexPoint>
{
public readonly int x;
public readonly int y;
public readonly int z;
// Some custom methods for initializations and operators
}
Run Code Online (Sandbox Code Playgroud)
如果我将 x、y 和 z 变量设为非只读,它们就会在统一检查器中正常显示。但是,我有一些他们需要满足的规则(实际上是 x+y+z=0),所以我添加了 readonly 以防止人们弄乱它。
但是作为只读变量,它们不会显示(因为它们不能被修改)!:(
我想知道它们是否是我在统一检查器中显示它们的一种方式,类似于 PropertyDrawer。我知道我可以将我的结构切换到一个类,因为 PropertyDrawer 是为类保留的,但我想将它保留为一个结构。
那么,有没有办法显示值?并最终使用自定义初始值设定项修改它们?
非常感谢!
c# ×8
asp.net-core ×3
angular ×2
.net ×1
asp.net-mvc ×1
form-submit ×1
grpc ×1
localization ×1
microsoft-identity-platform ×1
oauth-2.0 ×1
struct ×1
unity-editor ×1
webview2 ×1
wpf ×1