在.net 4.8中,我们像这样使用HttpContext
HttpContext.Current.Session["Settings"]) as List<UserSettings>
但在.net内核中,它给出了一个错误,无法将字符串转换为列表。
_accessor.HttpContext.Session.GetString("Settings")) as List<UserSettings>
我目前正在尝试将ASP.Net MVC API 4.6.2应用程序迁移到ASP.Net Core2.1。
private static string GetSessionId()
{
// Get from the session state, most reliable, but not likely available
if (HttpContext.Current.Session != null && !string.IsNullOrEmpty(HttpContext.Current.Session.SessionID))
如何在.net核心中创建这样的owin上下文,以便我可以使用用户和角色管理器?
public void ConfigureAuth(IAppBuilder app)
{
// Configure the db context, user manager and signin manager to use a single instance per request
//app.CreatePerOwinContext(ApplicationDbContext.Create);
app.CreatePerOwinContext<Ap
在我的asp.net MVC项目中,我有一个会话帮助类,用于设置和检索会话值。这是一堂课:
public class SessionManager
{
public static string UserName
{
get
{
return HttpContext.Current.Session[SessConstants.UName] ;
}
set
{
HttpContext.Current.Session[SessConstants.UName
我正在将asp net mvc中的一个旧应用程序升级到一个带有asp核+角7的新版本。在旧的应用程序中,我们有一个外部服务调用我们的api,并在URL中发送auth令牌,因为它不能这样做。
我拦截它将令牌注入到标题中,如下所示:
public class MvcApplication : System.Web.HttpApplication
{
protected void Application_PreSendRequestHeaders()
{
Response.Headers.Remove("X-Frame-Options");
我想动态地生成导航菜单,它遵循我的应用程序的默认路由,具有特定的操作和控制器。我在MVC5中解决了这个问题,但我不知道如何在.Net Core应用程序中这样做。
我在MVC5中所做的尝试如下:
视图模型:
public class MenuViewModel
{
// other props
public string Link
{
get
{
UrlHelper url = new UrlHelper(HttpContext.Current.Request.RequestContext);
我使用授权处理程序将自定义授权放入.net核心的控制器中。如何从控制器获取参数并将其用于授权处理程序? 在旧的.NET中,我可以从HttpContext请求参数中获得参数,如下所示: var eventId = filterContext.RequestContext.HttpContext.Request.Params["id"]; 我不知道如何在.net核心中实现它 public class HasAdminRoleFromAnySiteRequirement : AuthorizationHandler<HasAdminRoleFromAnySiteRequire
我正在使用ASP.NET Core5实现一个应用程序接口,并且我已经使用一个属性添加了响应缓存。现在,为了调试和跟踪的目的,我想将日志记录添加到这个属性中。
所以我的代码看起来像这样
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method)]
public class CachedAttribute : Attribute, IAsyncActionFilter
{
private readonly int _timeToLiveSeconds;
public CachedAttribute(int t
我正在将项目从Net迁移到MVC核心2。
如何在会话中设置IQueryable?在Net中,它是这样的,
public ActionResult CurrentOwners_Read([DataSourceRequest]DataSourceRequest request, int propertyID)
{
if (propertyID == 0)
{
throw new ArgumentNullException("propertyID");
}
IQueryable&
我们在服务层上有一个代码,用于获取sessionID并传递到外部API以进行会话关联。
public static string GetCorrelationSession()
{
if (HttpContext.Current != null && HttpContext.Current.Session != null)
{
//do some check and
if (!HttpContext.Current.User.Identity.IsAuthenticated | userContext == null)