我正在从MVC转向SPA + API方法,我正在制作一个新的应用程序,我正面临一些我似乎无法找到答案的问题.
我在.Net Core 2中有一个Web API,它使用Identity作为其用户存储.我通过发出JWT令牌来保护API,我的SPA在每次向我的控制器发出请求时作为承载令牌发送.发行代码是:
private async Task<object> GenerateJwtTokenAsync(ApplicationUser user)
{
var roles = await _userManager.GetRolesAsync(user);
var claims = new List<Claim>
{
new Claim(JwtRegisteredClaimNames.Sub, user.Email),
new Claim(JwtRegisteredClaimNames.Jti, Guid.NewGuid().ToString()),
new Claim(ClaimTypes.NameIdentifier, user.Id)
};
claims.AddRange(roles.Select(role => new Claim(ClaimTypes.Role, role)));
var key = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(_configuration["JwtKey"]));
var creds = new SigningCredentials(key, SecurityAlgorithms.HmacSha256);
var expires = DateTime.Now.AddDays(Convert.ToDouble(_configuration["JwtExpireDays"]));
var token = new JwtSecurityToken(
_configuration["JwtIssuer"],
_configuration["JwtIssuer"],
claims,
expires: expires,
signingCredentials: creds
);
return new JwtSecurityTokenHandler().WriteToken(token);
}
Run Code Online (Sandbox Code Playgroud)
我的问题是:获取在控制器中提供请求所需的用户信息的最佳做法是什么?
当我获得JWT令牌时,我有用户信息,但是关于用户的扩展信息,例如他们所在的公司是在我的SQL数据库中.
// GET: api/Agreements
[HttpGet]
public async Task<IEnumerable<Agreement>> …Run Code Online (Sandbox Code Playgroud) authorization jwt asp.net-identity asp.net-core asp.net-core-2.0
我正在逐行读取分隔符分隔的文件,并通过分隔符'|'拆分输入 在文件中使用的那些.在读取行时,我需要将"1.9"或"2.38"之类的输入转换为浮点数,但我似乎无法使其工作.我得到的是第一个数字,如"1"或"2".
我的代码出了什么问题?我的Struct person看起来像这样:
struct person {
string firstname;
string lastname;
string signature;
float length;
string getFullName() {
return firstname + " " + lastname;
}
};
Run Code Online (Sandbox Code Playgroud)
我的方法:
vector<person> LoadFromFile(string filename) {
string line;
vector<person> listToAddTo;
person newPerson;
ifstream infile(filename);
if (!infile) {
cerr << "Error opening file." << endl;
//Error
}
while (getline(infile, line)) {
string field;
vector<string> fields;
istringstream iss_line(line);
while (getline(iss_line, field, DELIM)) {
fields.push_back(field);
}
newPerson.firstname = fields[0];
newPerson.lastname = fields[1];
newPerson.length = strtof((fields[2]).c_str(),0);
newPerson.signature …Run Code Online (Sandbox Code Playgroud) 我通过组件中的计算属性在我的 vue-app 中动态渲染 V-select,但我的选择填充了 [object Object] 而不是值。如何设置名称属性?我这样做错了吗?
下拉菜单是它自己的组件:
<template>
<v-select
:items="listOfCompanys"
label="Lokation"
item-value="name"
item-text="name"
single-line
bottom
></v-select>
</template>
<script>
export default {
name: 'companydropdown',
computed: {
listOfCompanys () {
return this.$store.state.users.userList
}
}
}
</script>
Run Code Online (Sandbox Code Playgroud)
我得到的值是这样的: