- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
如何在 Restful 响应中保持区分大小写?
我的 friend 提示 RESTful 响应区分大小写
文件*.csproj
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<UserSecretsId>4942e08e-0489-4b66-ab36-7c1376ecb8a8</UserSecretsId>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="AWSSDK" Version="2.3.55.2" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="5.0.0-preview.8.20414.8" />
<PackageReference Include="Microsoft.AspNetCore.Cors" Version="2.2.0" />
<PackageReference Include="Microsoft.AspNetCore.Identity" Version="2.2.0" />
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="5.0.0-preview.8.20414.8" />
<PackageReference Include="Microsoft.AspNetCore.Identity.UI" Version="5.0.0-preview.8.20414.8" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="5.0.0-preview.8.20407.4" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="5.0.0-preview.8.20407.4" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="5.0.0-preview.8.20407.4">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.Extensions.Identity.Core" Version="5.0.0-preview.8.20414.8" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="5.0.0-preview.8.20419.1" />
<PackageReference Include="MimeKit" Version="2.9.1" />
<PackageReference Include="NAudio" Version="1.10.0" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
<PackageReference Include="NUnit" Version="3.12.0" />
<PackageReference Include="RestSharp" Version="106.11.5-alpha.0.18" />
<PackageReference Include="SendGrid" Version="9.21.0" />
<PackageReference Include="Serilog" Version="2.10.0-dev-01240" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="5.5.1" />
<PackageReference Include="Swashbuckle.AspNetCore.Annotations" Version="5.5.1" />
<PackageReference Include="Swashbuckle.AspNetCore.Swagger" Version="5.5.1" />
<PackageReference Include="Swashbuckle.AspNetCore.SwaggerGen" Version="5.5.1" />
<PackageReference Include="Swashbuckle.AspNetCore.SwaggerUI" Version="5.5.1" />
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.10.9" />
<PackageReference Include="System.ServiceModel.Syndication" Version="5.0.0-preview.8.20407.11" />
<PackageReference Include="System.Text.Encoding.CodePages" Version="5.0.0-preview.8.20407.11" />
<PackageReference Include="Twilio" Version="5.46.2" />
<PackageReference Include="Twilio.AspNet.Core" Version="5.33.1" />
</ItemGroup>
</Project>
/// <summary>
/// GET: http://localhost:5002/TrustedPerson/5
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
[HttpGet("{id}")]
public async Task<ActionResult<TrustedPerson>> ViewTrustedPerson(int id)
{
var item = await _db.TrustedPeople.FindAsync(id);
if (item == null)
{
return NotFound();
}
return item;
}
和
using Microsoft.AspNetCore.Authentication.JwtBearer;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Identity;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.IdentityModel.Tokens;
using shadow.Data;
using shadow.Services;
using System.Text;
using Microsoft.Extensions.FileProviders;
using System.IO;
using shadow.Models;
using Microsoft.AspNetCore.Authorization;
namespace shadow
{
public class Startup
{
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}
public IConfiguration Configuration { get; }
public void ConfigureServices(IServiceCollection services)
{
services.AddDbContext<ApplicationDbContext>(options => options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")));
services.AddHttpContextAccessor();
//services.AddCors();
services.AddCors(options =>
{
options.AddPolicy("CorsPolicy",
builder => builder.AllowAnyOrigin()
.AllowAnyMethod()
.AllowAnyHeader());
});
services.AddSingleton<IUriService>(o =>
{
var accessor = o.GetRequiredService<IHttpContextAccessor>();
var request = accessor.HttpContext.Request;
var uri = string.Concat(request.Scheme, "://", request.Host.ToUriComponent());
return new UriService(uri);
});
services.AddIdentity<ApplicationUser, IdentityRole>(options =>
{
//options.Password.RequireDigit = true;
//options.Password.RequireLowercase = true;
options.Password.RequiredLength = 6;
}).AddEntityFrameworkStores<ApplicationDbContext>().AddDefaultTokenProviders();
services
.AddAuthentication(auth =>
{
auth.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
auth.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme;
})
.AddJwtBearer(options =>
{
options.TokenValidationParameters = new Microsoft.IdentityModel.Tokens.TokenValidationParameters
{
ValidateIssuer = true,
ValidateAudience = true,
ValidAudience = Configuration["AuthSettings:Audience"],
ValidIssuer = Configuration["AuthSettings:Issuer"],
RequireExpirationTime = true,
IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(Configuration["AuthSettings:Key"])),
ValidateIssuerSigningKey = true
};
});
services.AddAuthorization(options =>
{
options.FallbackPolicy = new AuthorizationPolicyBuilder()
.RequireAuthenticatedUser()
.Build();
});
services.AddScoped<IUserService, UserService>();
services.AddTransient<IMailService, SendGridMailService>();
services.AddControllers();
services.AddRazorPages();
services.AddControllers(options => options.SuppressAsyncSuffixInActionNames = false);
}
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
//app.UseHttpsRedirection();
app.UseRouting();
// app.UseCors(options => options.WithOrigins("http://localhost:4200")
//.AllowAnyOrigin().AllowAnyMethod().AllowAnyHeader());
app.UseCors("CorsPolicy");
app.UseAuthentication();
app.UseAuthorization();
// Server: https://shorten.news/static-file/content/10992.mp3
// Local: http://localhost:5000/static-file/content/10992.mp3
app.UseStaticFiles(new StaticFileOptions
{
FileProvider = new PhysicalFileProvider(
// Path.Combine(env.ContentRootPath, @"c:\audio\")),
Path.Combine(@"c:\audio\")),
RequestPath = "/static-file"
});
app.UseEndpoints(endpoints =>
{
endpoints.MapControllers();
});
}
}
}
模型
using System;
#nullable disable
namespace shadow.Models
{
public partial class TrustedPerson
{
public int Id { get; set; }
public string Fullname { get; set; }
public string AliasName { get; set; }
public string Email { get; set; }
public string PhoneNumber1 { get; set; }
public string PhoneNumber2 { get; set; }
public string PhoneNumber3 { get; set; }
public int? RelationshipId { get; set; }
public string About { get; set; }
public int? AvatarId { get; set; }
public DateTime? Created { get; set; }
public DateTime? Modified { get; set; }
}
}
回复如
{
"id": 1,
"fullname": "Do Xxx Xx",
"aliasName": "Xx ham",
"email": "xxdn@xxsolutioxx.io",
"phoneNumber1": "0989878776",
"phoneNumber2": "0989878777",
"phoneNumber3": "0989878778",
"relationshipId": 3,
"about": "Dep trai",
"avatarId": 42,
"created": "2020-09-05T10:34:39.427",
"modified": null
}
我的 friend 想要
{
"Id": 1,
"Fullname": "Do Xxx Xx",
"AliasName": "Xx ham",
"Email": "xxdn@xxsolutioxx.io",
"PhoneNumber1": "0989878776",
"PhoneNumber2": "0989878777",
"PhoneNumber3": "0989878778",
"RelationshipId": 3,
"About": "Dep trai",
"AvatarId": 42,
"Created": "2020-09-05T10:34:39.427",
"Modified": null
}
(2)
(2) 是最佳实践吗?
如何像C#模型一样在RESTful响应的key中保持大小写敏感?
最佳答案
添加这一行
services.AddJsonOptions(options => { options.JsonSerializerOptions.PropertyNamingPolicy = null; });
关于c# - 如何在 Restful 响应中保持区分大小写?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63787119/
不确定是否可能,但只是想知道 CSS 中是否有一种方法来区分两种浏览器,即 IE6 和 IE8,因为我有一个我需要应用的样式,但 IE6 和 IE8 的值需要不同,即 ul.sf-menu li li
我正在为 C 库编写 C++ 抽象。 C 库有几个用于标识远程资源的 ID 的类型定义: typedef int color_id; typedef int smell_id; typedef int
有谁知道当以编程方式遍历 Word 文档时,您可以判断一个段落是否构成目录的一部分(或者实际上,构成字段一部分的任何其他内容)。 我提出这个问题的原因是我有一个 VB 程序,它应该从文档中提取前几段实
假设我的数据集包含三列:id(标识)、case(字符)和 value(数字)。这是我的数据集: tdata <- data.frame(id=c(1,1,1,1,2,2,2,2,3,3,3,3,4,4
我在解释 gcc (4.8.2) 警告和错误时遇到问题。更准确地说,很难分辨一个问题在哪里结束,另一个问题从哪里开始。我只能通过控制台访问构建机器,因此不能选择使用 IDE。 我真的需要能够快速区分个
我想创建一个泛型类型,它只从类定义中选择修饰的方法。 function test(ctor: any, methodName: any) {} class A { @test publ
是否有规范的 base-R 方法来确定函数参数是否是对象名称而不是文字/表达式? 虽然通常不鼓励使用 NSE,但偶尔会有人有一个好主意并想使用它。 data.frame 是我认为“方便”的最简单用例:
我已经实现了 didSelectRowAtIndexPath 和accessoryButtonTappedForRowWithIndexPath 似乎永远不会触发。但是,didSelectRowAtI
我需要确定数据框中的哪些列是小数,哪些是字符串。 使用 df.dtypes 为两种列类型提供“对象”: import pandas as pd import decimal data = {'dec1
有没有办法在 Vim 中区分隐藏缓冲区和事件缓冲区? 我需要确定窗口中的缓冲区是否处于事件状态,以便可以切换它。 尝试了 bufloaded、bufexists 和 buflisted,但它们对于事件
在 JavaScript 中区分事件的最佳方法是什么。 实际上有两点我感兴趣。第一点是事件中是否有类似 id 的东西(这对于调试目的非常有用)。另一点是有更好的方法来区分 mousedown 和 mo
我有一个 php 页面,里面有多个表单。 "> "> " value=""> " value=""> 这些表单是通过循环遍历 MySQL 上的所有数据而生成的。每个表单和输入都
Pony 有一个未参数化的异常值。 不幸的是,我经常有一些代码想要抛出不同类型的异常,并且我需要知道它们是什么,以便正确处理它们——例如,简单地说,当停止程序时,向用户提供以下信息很重要正确的错误消息
出于对所有神圣事物的热爱,您如何区分预定义的 .NET 异常类中的不同“异常风格”? 例如,一段代码可能会抛出 XmlException在以下条件下: 文档的根元素为NULL 文档中的字符无效 文档太
正如您在下面看到的,我创建了一个 JComboBox,其中“选项”数组中的元素作为列表中的选项。 当选择列表中的特定项目时,我想显示 JLabels“一个”或“两个”。例如。选择选项一显示“一”,选择
我有一个表,其中包含四列用户名、产品名称、产品价格和一个名为 item_paid 的 boolean 列。相同的产品名称可以作为重复条目插入到表中。但是有没有办法区分一行和重复行?或者我应该创建一个名
是否可以使用反射来区分仅 getter 属性和表达式主体属性? class MyClass { DateTime GetterOnly { get; } DateTime Expres
我即将为一个学校项目制作一个小程序,该程序应该能够识别通过 MIDI 钢琴输入演奏的和弦(这只是其中的一部分)。 目前为止,每次按下和每次释放 MIDI 键盘上的某个键,我都会得到一个 ShortMe
我正在使用“自动”反序列化器从 Kafka 消费 Avro 序列化消息,例如: props.put( ConsumerConfig.VALUE_DESERIALIZER_CLASS_CONFI
我需要从两个表中检索数据。第一个是事件列表,第二个是 field 列表。 我在两个表中都有一个同名的字段:events.venue(这是一个 ID),venues.venue 是地点的名称,比如“bl
我是一名优秀的程序员,十分优秀!