VS2022 MVC和WebApi使用Session的细节。
在NETFW6.0 MVC框架中使用session添加两行代码即可。
builder.Services.AddSession();
app.UseSession();
在WebAPI框架中:
多加一行
builder.Services.AddDistributedMemoryCache();
builder.Services.AddSession();
app.UseSession();
搞定……
.相关错误提示:
System.AggregateException:“Some services are not able to be constructed (Error while validating the service descriptor ‘ServiceType: Microsoft.AspNetCore.Session.ISessionStore Lifetime: Transient ImplementationType: Microsoft.AspNetCore.Session.DistributedSessionStore’: Unable to resolve service for type ‘Microsoft.Extensions.Caching.Distributed.IDistributedCache’ while attempting to activate ‘Microsoft.AspNetCore.Session.DistributedSessionStore’.)”
博客介绍了VS2022中MVC和WebApi使用Session的细节。在NETFW6.0 MVC框架中使用session添加两行代码即可,WebAPI框架中需多加一行。还给出了相关错误提示,如无法解析特定服务类型的问题。
2668

被折叠的 条评论
为什么被折叠?



