小编bno*_*man的帖子

如何在 Angular 5 中动态设置选定的下拉值

我正在尝试设置 Angular 5 中下拉列表的选定值。

HTML:

<mat-form-field class="col-sm-3">
   <mat-select placeholder="State" name="state [formControl]="stateFormControl" required>
     <mat-option *ngFor="let state of states" value="{{state.key}}">{{state.name}}
     </mat-option>
   </mat-select>
   <mat-error *ngIf="stateFormControl.hasError('required')">State is required
   </mat-error>
</mat-form-field>
Run Code Online (Sandbox Code Playgroud)

打字稿:

stateFormControl = new FormControl('', [
    Validators.required
]);

this.vendorForm.controls["state"].setValue(this.state);
Run Code Online (Sandbox Code Playgroud)

即使我在 FormControl 声明中设置默认值,默认情况下也不会为下拉列表设置任何内容。

typescript angular

5
推荐指数
1
解决办法
1万
查看次数

在 MVC .Net Core Mvc 21 中将授权标头添加到 HttpContext

我有一个 Jwt Bearer 令牌,我将其存储在 .Net Core 2.1 应用程序的会话中。在我的中间件中,我通过以下方式拦截请求并将令牌附加到标头:

httpContext.Request.Headers.Add("Authorization", $"Bearer {token}");
Run Code Online (Sandbox Code Playgroud)

目前此功能不起作用,因为我在受保护的路线上获得了未经授权的权限。如果我使用邮递员进行相同的调用并在标头中传递授权和承载令牌,则它可以工作。

我需要对 http.Request 进行哪些更改才能使其可接受?

使用 Jwt 启动的部分: varsigningKey = key;

        services.AddSingleton<IJwtFactory, JwtFactory>();

        var jwtAppSettingOptions = Configuration.GetSection(nameof(JwtIssuerOptions));

        // Configure JwtIssuerOptions
        services.Configure<JwtIssuerOptions>(options =>
        {
            options.Issuer = Issuer;
            options.Audience = Audience;
            options.SigningCredentials = new SigningCredentials(signingKey, SecurityAlgorithms.HmacSha256);
        });

        services.AddAuthentication(options =>
        {
            options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
            options.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme;
        })
            .AddJwtBearer(options =>
            {
                options.RequireHttpsMetadata = false;
                options.SaveToken = true;
                options.TokenValidationParameters = new TokenValidationParameters
                {
                    ValidateIssuer = true,
                    ValidIssuer = Issuer,

                    ValidateAudience = true,
                    ValidAudience = …
Run Code Online (Sandbox Code Playgroud)

.net model-view-controller asp.net-core

5
推荐指数
1
解决办法
4565
查看次数