关于asp.netcore自定义Content-Type和asp.netcore自定义成功页面的问题就给大家分享到这里,感谢你花时间阅读本站内容,更多关于.NETCore中WebOperationCo
关于asp.net core 自定义 Content-Type和asp.net core 自定义成功页面的问题就给大家分享到这里,感谢你花时间阅读本站内容,更多关于.NET Core 中 WebOperationContext.Current.OutgoingResponse.ContentType 的替代方法是什么、.net core 调用 webservice 错误:content type does not match、aiohttp.client_exceptions.ContentTypeError: 0:json(content_type=‘??‘)、ASP.NET Core Identity自定义数据库结构和完全使用Dapper而非EntityFramework Core等相关知识的信息别忘了在本站进行查找喔。
本文目录一览:- asp.net core 自定义 Content-Type(asp.net core 自定义成功页面)
- .NET Core 中 WebOperationContext.Current.OutgoingResponse.ContentType 的替代方法是什么
- .net core 调用 webservice 错误:content type does not match
- aiohttp.client_exceptions.ContentTypeError: 0:json(content_type=‘??‘)
- ASP.NET Core Identity自定义数据库结构和完全使用Dapper而非EntityFramework Core
asp.net core 自定义 Content-Type(asp.net core 自定义成功页面)
asp.net core 实现支持自定义 Content-Type
Intro
我们最近有一个原本是内网的服务要上公网,在公网上有一层 Cloudflare
作为网站的公网流量提供者,CloudFlare 会有一层防火墙拦截掉一些非法的请求,我们有一些 API 会提交一些 html 内容,经过 Cloudflare
的时候会被 Cloudflare
拦截,导致某些功能不能够正常使用,于是就想对提交的数据进行一个编码之后再提交,服务器端针对需要解码的请求进行解码再解析,我们新加了一个 Content-Type
的支持,编码后的数据使用新的 Content-Type
,对于不编码的数据依然可以工作,目前我们做了一个简单的 base64 编码,如果需要的话也可以实现复杂一些的加密、压缩等。
Basis
asp.net core 默认支持 JSON 请求,因为内置了针对 JSON 内容的 Formatter
,.NET Core 2.x 使用的是 Newtonsoft.Json
作为默认 JSON formatter,从 .NET Core 3.0 开始引入了 System.Text.Json
作为默认的 JSON formatter,如果要支持 XML 需要引入针对 XML 的 formatter,相应的如果需要增加其他类型的请求实现自己的 formatter 就可以了
Formatter 分为 InputFormatter
和 OutputFormatter
-
InputFormatter
用来解析请求Body
的数据,将请求参数映射到强类型的 model,Request Body => Value -
OutputFormatter
用来将强类型的数据序列化成响应输出,Value => Response Body
Formatter 需要指定支持的 MediaType
,可以理解为请求类型,体现在请求头上,对于 InputFormatter
对应的就是 Content-Type
,对于 OutputFormatter
对应的是 Accept
,asp.net core 会根据请求信息来选择注册的 formatter。
Sample
先来看一下实现效果吧,实现效果如下:

swagger 的支持也算比较好了,在增加了新的 Content-Type
支持之后在 swagger 上可以看得到,而且可以切换请求的 Content-Type
,上图中的 text/base64-json
就是我自定义的一个 Content-Type
默认请求:

对原始请求进行 base64 编码,再请求:

Implement
实现代码如下:
public class Base64EncodedJsonInputFormatter : TextInputFormatter
{
public Base64EncodedJsonInputFormatter()
{
// 注册支持的 Content-Type
SupportedMediaTypes.Add("text/base64-json");
SupportedEncodings.Add(Encoding.UTF8);
}
public override async Task<InputFormatterResult> ReadRequestBodyAsync(InputFormatterContext context, Encoding encoding)
{
try
{
using var reader = context.ReaderFactory(context.HttpContext.Request.Body, encoding);
var rawContent = await reader.ReadToEndAsync();
if (string.IsNullOrEmpty(rawContent))
{
return await InputFormatterResult.NoValueAsync();
}
var bytes = Convert.FromBase64String(rawContent);
var services = context.HttpContext.RequestServices;
var modelValue = await GetModelValue(services, bytes);
return await InputFormatterResult.SuccessAsync(modelValue);
async ValueTask<object> GetModelValue(IServiceProvider serviceProvider, byte[] stringBytes)
{
var newtonJsonOption = serviceProvider.GetService<IOptions<MvcNewtonsoftJsonOptions>>()?.Value;
if (newtonJsonOption is null)
{
await using var stream = new MemoryStream(stringBytes);
var result = await System.Text.Json.JsonSerializer.DeserializeAsync(stream, context.ModelType,
services.GetRequiredService<IOptions<JsonOptions>>().Value.JsonSerializerOptions);
return result;
}
var stringContent = encoding.GetString(bytes);
return Newtonsoft.Json.JsonConvert.DeserializeObject(stringContent, context.ModelType, newtonJsonOption.SerializerSettings);
}
}
catch (Exception e)
{
context.ModelState.TryAddModelError(string.Empty, e.Message);
return await InputFormatterResult.FailureAsync();
}
}
}
上述代码兼容了使用 System.Text.Json
和 Newtonsoft.Json
,在发生异常时将错误信息添加一个 ModelError
以便在前端可以得到错误信息的反馈,例如传一个不合法的 base64 字符串就会像下面这样:

实际使用的时候,只需要在 Startup
里配置一下就可以了,如:
services.AddControllers(options =>
{
options.InputFormatters.Add(new Base64EncodedJsonInputFormatter());
});
More
通过自定义 Content-Type
的支持我们可以无侵入的实现不同的请求内容,上面的示例代码可以在 Github 上获取 https://github.com/WeihanLi/SamplesInPractice/tree/master/AspNetCoreSample,可以根据自己的需要进行自定义
References
-
https://docs.microsoft.com/en-us/aspnet/core/web-api/advanced/custom-formatters?view=aspnetcore-5.0 -
https://github.com/dotnet/AspNetCore.Docs/tree/main/aspnetcore/web-api/advanced/custom-formatters/samples -
https://github.com/WeihanLi/SamplesInPractice/tree/master/AspNetCoreSample
本文分享自微信公众号 - dotNET 跨平台(opendotnet)。
如有侵权,请联系 support@oschina.cn 删除。
本文参与 “OSC 源创计划”,欢迎正在阅读的你也加入,一起分享。
.NET Core 中 WebOperationContext.Current.OutgoingResponse.ContentType 的替代方法是什么
如何解决.NET Core 中 WebOperationContext.Current.OutgoingResponse.ContentType 的替代方法是什么?
.NET Core 中以下代码片段的替代方法是什么?
WebOperationContext webContext = WebOperationContext.Current;
webContext.OutgoingResponse.ContentType = "text/html";
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)
.net core 调用 webservice 错误:content type does not match
.net core 调用 webservice 错误:content type does not match
The content type text/xml; charset="utf-8" of the response message does not match the content type of the binding (text/xml; charset=utf-8).
If using a custom encoder, be sure that the IsContentTypeSupported method is implemented properly. The first 1024 bytes of the response were: ''<?xml version=''1.0'' encoding=''UTF-8''?> [...]
错误原因
直接原因是 text/xml; charset="utf-8" 与 text/xml; charset=utf-8 不匹配,utf-8 多了双引号。 根本原因,微软.net wcf 库的 bug.
解决
网上很多人提,就是没提解决方案,其实很简单:升级相关库即可。 升级:System.ServiceModel.* 类库到最新版,自动解决。
aiohttp.client_exceptions.ContentTypeError: 0:json(content_type=‘??‘)
aiohttp.client_exceptions
- 问题
- 解决
问题
# 获取异步requests
async with aiohttp.ClientSession() as session:
async with session.post(url, headers=headers, data=data) as resp:
# 写入数据
csvWriter.writerow(await resp.json()) # 读取内容是异步的,需要挂起
print('库编号', data['p'], '爬取完毕!')
from aioHTTP_Requests import requests
async def req(URL):
headers = {"Accept": 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8',
"Accept-Language": "zh-CN,zh;q=0.9", "Host": "xin.baidu.com",
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML,like Gecko) Chrome/72.0.3626.121 Safari/537.36", }
resp = await requests.get(URL,headers=headers,timeout=10,verify_ssl=False)
resp_text = await resp.json(encoding='utf-8')
return resp_text
if __name__ == "__main__":
print("HELLO WORLD")
URL = "https://xin.baidu.com/detail/basicAjax?pid=xlTM-TogKuTw9PzC-u6VwZxUBuZ5J7WMewmd"
loop = asyncio.get_event_loop()
loop.run_until_complete(req(URL))
csvWriter.writerow(await resp.json())
运行上面的程序会报错
解决
ContentTypeError:类型错误
在resp.json()
:传入编码文本类型参数即可:
resp.json(content_type='text/html',encoding='utf-8')
参考:Link
衷心感谢!
ASP.NET Core Identity自定义数据库结构和完全使用Dapper而非EntityFramework Core
前言
原本本节内容是不存在的,出于有几个人问到了我:我想使用ASP.NET Core Identity,但是我又不想使用默认生成的数据库表,想自定义一套,我想要使用ASP.NE Core Identity又不想使用EntityFramework Core。真难伺候,哈哈,不过我认为这个问题提出的非常有价值,所以就私下花了点时间看下官网资料,最终经过尝试还是搞出来了,不知道是否满足问过我这个问题的几位童鞋,废话少说,我们直接进入主题吧。
ASP.NET Core Identity自定义数据库表结构
别着急哈,我是那种从头讲到尾的人,博文基本上面向大众,没什么基础的和有经验的都能看明白,也不要嫌弃我啰嗦,好,我说完了,开始,开始,又说了一大堆。大部分情况下对于默认情况下我们都是继承自默认的身份有关的类,如下:
/// <summary>
///
/// </summary>
public class CusomIdentityDbContext : IdentityDbContext<CustomIdentityUser, CustomIdentityRole, string>
{
/// <summary>
///
/// </summary>
/// <param name="options"></param>
public CusomIdentityDbContext(DbContextOptions<CusomIdentityDbContext> options)
: base(options)
{ }
}
/// <summary>
///
/// </summary>
public class CustomIdentityUser : IdentityUser { }
/// <summary>
///
/// </summary>
public class CustomIdentityRole : IdentityRole { }
然后添加身份中间件,最后开始迁移,如下:
services.AddIdentity<CustomIdentityUser, IdentityRole>()
.AddEntityFrameworkStores<CusomIdentityDbContext>()
.AddDefaultTokenProviders();
services.AddDbContextPool<CusomIdentityDbContext>(options =>
options.UseSqlServer(Configuration.GetConnectionString("Default")));
以上是默认为我们生成的数据表,我们可以指定用户表主键、可以修改表名、列名等等,以及在此基础上扩展属性都是可以的,但是我们就是不想使用这一套,需要自定义一套表来管理用户身份信息,那么我们该如何做呢?其实呢,官网给了提示,
如下链接:https://docs.microsoft.com/en-us/aspnet/core/security/authentication/identity-custom-storage-providers?view=aspnetcore-2.2,只是说的不是很明确,然后有些童鞋就不知所措了,就是那么几个Store,自定义实现就好了,来,我们走一个。我们首先自定义用户,比如如下:
/// <summary>
///
/// </summary>
public class User
{
/// <summary>
///
/// </summary>
public string Id { get; set; }
/// <summary>
///
/// </summary>
public string UserName { get; set; }
/// <summary>
///
/// </summary>
public string Password { get; set; }
/// <summary>
///
/// </summary>
public string Phone { get; set; }
}
我们再来定义上下文,如下:
/// <summary>
///
/// </summary>
public class CustomDbContext : DbContext
{
/// <summary>
///
/// </summary>
/// <param name="options"></param>
public CustomDbContext(DbContextOptions<CustomDbContext> options) : base(options)
{
}
/// <summary>
///
/// </summary>
public DbSet<User> Users { get; set; }
}
接下来实现IUserStore以及UserPasswordStore接口,接口太多,就全部折叠了


/// <summary>
///
/// </summary>
public class CustomUserStore : IUserStore<User>, IUserPasswordStore<User>
{
private readonly CustomDbContext context;
/// <summary>
///
/// </summary>
/// <param name="context"></param>
public CustomUserStore(CustomDbContext context)
{
this.context = context;
}
/// <summary>
///
/// </summary>
/// <param name="user"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public Task<IdentityResult> CreateAsync(User user, CancellationToken cancellationToken)
{
throw new NotImplementedException();
}
/// <summary>
///
/// </summary>
/// <param name="user"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public Task<IdentityResult> DeleteAsync(User user, CancellationToken cancellationToken)
{
throw new NotImplementedException();
}
/// <summary>
///
/// </summary>
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}
/// <summary>
///
/// </summary>
/// <param name="disposing"></param>
protected virtual void Dispose(bool disposing)
{
if (disposing)
{
context?.Dispose();
}
}
/// <summary>
///
/// </summary>
/// <param name="userId"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public Task<User> FindByIdAsync(string userId, CancellationToken cancellationToken)
{
throw new NotImplementedException();
}
/// <summary>
///
/// </summary>
/// <param name="normalizedUserName"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public Task<User> FindByNameAsync(string normalizedUserName, CancellationToken cancellationToken)
{
throw new NotImplementedException();
}
/// <summary>
///
/// </summary>
/// <param name="user"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public Task<string> GetNormalizedUserNameAsync(User user, CancellationToken cancellationToken)
{
throw new NotImplementedException();
}
/// <summary>
///
/// </summary>
/// <param name="user"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public Task<string> GetPasswordHashAsync(User user, CancellationToken cancellationToken)
{
throw new NotImplementedException();
}
/// <summary>
///
/// </summary>
/// <param name="user"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public Task<string> GetUserIdAsync(User user, CancellationToken cancellationToken)
{
throw new NotImplementedException();
}
/// <summary>
///
/// </summary>
/// <param name="user"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public Task<string> GetUserNameAsync(User user, CancellationToken cancellationToken)
{
throw new NotImplementedException();
}
/// <summary>
///
/// </summary>
/// <param name="user"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public Task<bool> HasPasswordAsync(User user, CancellationToken cancellationToken)
{
throw new NotImplementedException();
}
/// <summary>
///
/// </summary>
/// <param name="user"></param>
/// <param name="normalizedName"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public Task SetNormalizedUserNameAsync(User user, string normalizedName, CancellationToken cancellationToken)
{
throw new NotImplementedException();
}
/// <summary>
///
/// </summary>
/// <param name="user"></param>
/// <param name="passwordHash"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public Task SetPasswordHashAsync(User user, string passwordHash, CancellationToken cancellationToken)
{
throw new NotImplementedException();
}
/// <summary>
///
/// </summary>
/// <param name="user"></param>
/// <param name="userName"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public Task SetUserNameAsync(User user, string userName, CancellationToken cancellationToken)
{
throw new NotImplementedException();
}
/// <summary>
///
/// </summary>
/// <param name="user"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public Task<IdentityResult> UpdateAsync(User user, CancellationToken cancellationToken)
{
throw new NotImplementedException();
}
}
我们还要用到用户角色表,自定义用户角色
/// <summary>
///
/// </summary>
public class CustomUserRole
{
/// <summary>
///
/// </summary>
public string Id { get; set; }
/// <summary>
///
/// </summary>
public string UserId { get; set; }
/// <summary>
///
/// </summary>
public string RoleId { get; set; }
}
接下来再来实现用户角色Store,如下:
/// <summary>
///
/// </summary>
public class CustomUserRoleStore : IRoleStore<CustomUserRole>
{
/// <summary>
///
/// </summary>
/// <param name="role"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public Task<IdentityResult> CreateAsync(CustomUserRole role, CancellationToken cancellationToken)
{
throw new NotImplementedException();
}
/// <summary>
///
/// </summary>
/// <param name="role"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public Task<IdentityResult> DeleteAsync(CustomUserRole role, CancellationToken cancellationToken)
{
throw new NotImplementedException();
}
/// <summary>
///
/// </summary>
public void Dispose()
{
throw new NotImplementedException();
}
/// <summary>
///
/// </summary>
/// <param name="roleId"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public Task<CustomUserRole> FindByIdAsync(string roleId, CancellationToken cancellationToken)
{
throw new NotImplementedException();
}
/// <summary>
///
/// </summary>
/// <param name="normalizedRoleName"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public Task<CustomUserRole> FindByNameAsync(string normalizedRoleName, CancellationToken cancellationToken)
{
throw new NotImplementedException();
}
/// <summary>
///
/// </summary>
/// <param name="role"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public Task<string> GetNormalizedRoleNameAsync(CustomUserRole role, CancellationToken cancellationToken)
{
throw new NotImplementedException();
}
/// <summary>
///
/// </summary>
/// <param name="role"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public Task<string> GetRoleIdAsync(CustomUserRole role, CancellationToken cancellationToken)
{
throw new NotImplementedException();
}
/// <summary>
///
/// </summary>
/// <param name="role"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public Task<string> GetRoleNameAsync(CustomUserRole role, CancellationToken cancellationToken)
{
throw new NotImplementedException();
}
/// <summary>
///
/// </summary>
/// <param name="role"></param>
/// <param name="normalizedName"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public Task SetNormalizedRoleNameAsync(CustomUserRole role, string normalizedName, CancellationToken cancellationToken)
{
throw new NotImplementedException();
}
/// <summary>
///
/// </summary>
/// <param name="role"></param>
/// <param name="roleName"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public Task SetRoleNameAsync(CustomUserRole role, string roleName, CancellationToken cancellationToken)
{
throw new NotImplementedException();
}
/// <summary>
///
/// </summary>
/// <param name="role"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public Task<IdentityResult> UpdateAsync(CustomUserRole role, CancellationToken cancellationToken)
{
throw new NotImplementedException();
}
}
简单来说就是根据需要,看看要不要实现如下几个Store罢了
- IUserRoleStore
- IUserClaimStore
- IUserPasswordStore
- IUserSecurityStampStore
- IUserEmailStore
- IPhoneNumberStore
- IQueryableUserStore
- IUserLoginStore
- IUserTwoFactorStore
- IUserLockoutStore
然后对于根据选择自定义实现的Store都进行注册,然后进行迁移,如下:
services.AddIdentity<CustomUser, CustomUserRole>()
.AddDefaultTokenProviders();
services.AddDbContextPool<CustomDbContext>(options =>
options.UseSqlServer(Configuration.GetConnectionString("Default")));
services.AddTransient<IUserStore<CustomUser>, CustomUserStore>();
没什么难题,还是那句话,自定义实现一套,不过是实现内置的Store,其他通过定义的上下文正常去管理用户即可。然后什么登陆、注册之类只需要将对应比如UserManager泛型参数替换成对应比如如上CustomUser即可,这个就不用多讲了。接下来我们再来看第二个问题,如何不使用EntityFramework而是完全使用Dapper。
完全使用Dapper而不使用EntityFramework Core
其实讲解完上述第一个问题,这个就迎刃而解了,我们已经完全实现了自定义一套表,第一个问题操作表是通过上下文,我们只需将上下文更换为Dapper即可,如上我们定义了用户角色表,那我们通过Dapper实现角色表,如下定义角色:
/// <summary>
///
/// </summary>
public class CustomRole
{
/// <summary>
///
/// </summary>
public string Id { get; set; }
/// <summary>
///
/// </summary>
public string Name { get; set; }
}
/// <summary>
///
/// </summary>
public class CustomRoleStore : IRoleStore<CustomRole>
{
private readonly IConfiguration configuration;
private readonly string connectionString;
/// <summary>
///
/// </summary>
/// <param name="configuration"></param>
public CustomRoleStore(IConfiguration configuration)
{
this.configuration = configuration;
connectionString = configuration.GetConnectionString("Default");
}
/// <summary>
///
/// </summary>
/// <param name="role"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public async Task<IdentityResult> CreateAsync(CustomRole role, CancellationToken cancellationToken)
{
cancellationToken.ThrowIfCancellationRequested();
using (var connection = new SqlConnection(connectionString))
{
await connection.OpenAsync(cancellationToken);
role.Id = await connection.QuerySingleAsync<string>($@"INSERT INTO [CustomRole] ([Id],[Name])
VALUES (@{Guid.NewGuid().ToString()} @{nameof(CustomRole.Name)});
SELECT CAST(SCOPE_IDENTITY() as varchar(36))", role);
}
return IdentityResult.Success;
}
/// <summary>
///
/// </summary>
/// <param name="role"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public Task<IdentityResult> DeleteAsync(CustomRole role, CancellationToken cancellationToken)
{
throw new NotImplementedException();
}
/// <summary>
///
/// </summary>
public void Dispose()
{
throw new NotImplementedException();
}
/// <summary>
///
/// </summary>
/// <param name="roleId"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public Task<CustomRole> FindByIdAsync(string roleId, CancellationToken cancellationToken)
{
throw new NotImplementedException();
}
/// <summary>
///
/// </summary>
/// <param name="normalizedRoleName"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public Task<CustomRole> FindByNameAsync(string normalizedRoleName, CancellationToken cancellationToken)
{
throw new NotImplementedException();
}
/// <summary>
///
/// </summary>
/// <param name="role"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public Task<string> GetNormalizedRoleNameAsync(CustomRole role, CancellationToken cancellationToken)
{
throw new NotImplementedException();
}
/// <summary>
///
/// </summary>
/// <param name="role"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public Task<string> GetRoleIdAsync(CustomRole role, CancellationToken cancellationToken)
{
throw new NotImplementedException();
}
/// <summary>
///
/// </summary>
/// <param name="role"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public Task<string> GetRoleNameAsync(CustomRole role, CancellationToken cancellationToken)
{
return Task.FromResult(role.Name);
}
/// <summary>
///
/// </summary>
/// <param name="role"></param>
/// <param name="normalizedName"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public Task SetNormalizedRoleNameAsync(CustomRole role, string normalizedName, CancellationToken cancellationToken)
{
throw new NotImplementedException();
}
/// <summary>
///
/// </summary>
/// <param name="role"></param>
/// <param name="roleName"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public Task SetRoleNameAsync(CustomRole role, string roleName, CancellationToken cancellationToken)
{
throw new NotImplementedException();
}
/// <summary>
///
/// </summary>
/// <param name="role"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public Task<IdentityResult> UpdateAsync(CustomRole role, CancellationToken cancellationToken)
{
throw new NotImplementedException();
}
}
别忘记每自定义实现一个Store,然后进行对应注册
services.AddTransient<IRoleStore<CustomRole>, CustomRoleStore>();
总结
这里已经提供了完全自定义实现一套表和不使用EntityFramework Core完全使用Dapper的思路,重申一句官网给出了几个Store,只是未明确说明而已,稍微思考并动手验证,其实问题不大。
原文出处:https://www.cnblogs.com/CreateMyself/p/11291623.html
我们今天的关于asp.net core 自定义 Content-Type和asp.net core 自定义成功页面的分享就到这里,谢谢您的阅读,如果想了解更多关于.NET Core 中 WebOperationContext.Current.OutgoingResponse.ContentType 的替代方法是什么、.net core 调用 webservice 错误:content type does not match、aiohttp.client_exceptions.ContentTypeError: 0:json(content_type=‘??‘)、ASP.NET Core Identity自定义数据库结构和完全使用Dapper而非EntityFramework Core的相关信息,可以在本站进行搜索。
本文标签: