简体   繁体   English

在ASP.NET Core中输入操作之前先退出调试

[英]Get out the debug before entering the action in ASP.NET Core

I need to return Roles.Claims in ASP.NET Core for dynamic permission. 我需要在ASP.NET Core中返回Roles.Claims以获得动态权限。

When I enter this url : https://localhost:44390/api/Role/GetRoleClaims/1008 当我输入此URL时: https://localhost:44390/api/Role/GetRoleClaims/1008

this action will be executed: 该动作将被执行:

[HttpGet("GetRoleClaims/{id}")]
public Task<Role> GetRoleClaims(int? id)
{
    return _roleManag.ClaimsOfRole(id.Value);
}

then execution goes to the service layer and runs this method: 然后执行转到服务层并运行此方法:

public Task<Role> FindRoleIncludeRoleClaimsAsync(int roleId)
{
    return Roles.Include(x => x.Claims).FirstOrDefaultAsync(x => x.Id == roleId);
}

public async Task<Role> ClaimsOfRole(int id)
{
    var role = await FindRoleIncludeRoleClaimsAsync(id);
    return role;
}

The variable role is filled with the correct data, but it does not get back to the action after this line return role; 变量role填充有正确的数据,但是在此行return role;之后,它不会返回到操作return role;

It shows the web browser and shows this : 它显示了网络浏览器并显示了以下内容:

在此处输入图片说明

What is the problem? 问题是什么? How can I solve this problem? 我怎么解决这个问题?

Your ClaimsOfRole is still an async method and you are missing an await here: 您的ClaimsOfRole仍然是一个async方法,您await这里错过了一个await

[HttpGet("GetRoleClaims/{id}")]
public async Task<Role> GetRoleClaims(int? id)
{
    return await _roleManag.ClaimsOfRole(id.Value);
}

Your Secure Connection Failed error has nothing to do with that code. 您的“安全连接失败”错误与该代码无关。 It may be to do with: 可能与以下内容有关:

  1. asp.net core recently moved to https by default 最近默认将asp.net核心移至https
  2. https requires a certificate https需要证书
  3. The default for development is that microsoft has your machine generate a self-signed certificate 开发的默认设置是Microsoft使您的计算机生成自签名证书
  4. Browsers show an error message because the self-signed certificate isn't authorised by a certificate authority. 浏览器显示错误消息,因为自签名证书未得到证书颁发机构的授权。

Options: 选项:

Either that, or you've just typed in the wrong port. 要么,要么您输入的端口错误。 Where did you get 44390 from? 您从哪里获得44390

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM