C# 读取.Net核心Web Api中的本地存储值

C# 读取.Net核心Web Api中的本地存储值,c#,angular,asp.net-core,asp.net-core-webapi,C#,Angular,Asp.net Core,Asp.net Core Webapi,向web api发送get请求时,如何读取本地存储值? 目前我正在使用angular 8和jwt拦截器,该拦截器能够从localstorage读取令牌,但如何读取localstorage的所有属性 本地存储 控制器: [HttpGet] [Authorize] public ActionResult<IEnumerable<string>> Index() { //READ CurrentRole and Roleacce

向web api发送get请求时,如何读取本地存储值? 目前我正在使用angular 8和jwt拦截器,该拦截器能够从localstorage读取令牌,但如何读取localstorage的所有属性

本地存储

控制器:

    [HttpGet]
  [Authorize]

    public ActionResult<IEnumerable<string>> Index()
    { 
        //READ CurrentRole and Roleaccesslist here
    }
[HttpGet]
[授权]
公共行动结果索引()
{ 
//请在此处阅读当前角色和角色访问列表
}

您可以创建自己的HttpInterceptor,如:

@Injectable()
export class TokenInterceptor implements HttpInterceptor {

    constructor(private router: Router) { }


    intercept(request: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {

        request = request.clone({
            setHeaders: {
                Authorization: `Bearer ${localStorage.getItem('token')}`
            }
        }); return next.handle(request);
    }
}

@Markel我不是问令牌是如何发送到服务器的,你是说如何从本地存储读取数据?在发送到API之前?因此,我使用来自“@auth0/angular jwt”的import{JwtModule};导出函数GetToken(){return localStorage.getItem(environment.jwt_name);}和JwtModule.forRoot({config:{tokenGetter:GetToken,whitelistedDomains:['localhost:5000','localhost:5001']}),这就是你的意思吗?如果是这样,我会更新我的答案我只想发送本地存储值我更新了我的答案。我认为你问题的标题有点混乱,因为它表明你想在asp中读取本地存储值,这是不可能的。我同意。我被标题弄糊涂了:(
export function GetToken() {
   return localStorage.getItem(environment.jwt_name);
 }

 JwtModule.forRoot({
     config: {
       tokenGetter: GetToken,
       whitelistedDomains: ['localhost:5000', 'localhost:5001']
     }
  }),