👻 Elektrikli Erol👻
👻 Elektrikli Erol👻
CC#
Created by 👻 Elektrikli Erol👻 on 4/4/2023 in #help
❔ ASP.NET to .net Core
okay let me try ^^
29 replies
CC#
Created by 👻 Elektrikli Erol👻 on 4/4/2023 in #help
❔ ASP.NET to .net Core
oh okay thanks for help
29 replies
CC#
Created by 👻 Elektrikli Erol👻 on 4/4/2023 in #help
❔ ASP.NET to .net Core
okay then i split my functions related to httpcontext to a different class
29 replies
CC#
Created by 👻 Elektrikli Erol👻 on 4/4/2023 in #help
❔ ASP.NET to .net Core
yes you are right
29 replies
CC#
Created by 👻 Elektrikli Erol👻 on 4/4/2023 in #help
❔ ASP.NET to .net Core
So my approach is wrong .. what is the best approach here ?
29 replies
CC#
Created by 👻 Elektrikli Erol👻 on 4/4/2023 in #help
❔ ASP.NET to .net Core
No suitable constructor was found for entity type 'User'. The following constructors had parameters that could not be bound to properties of the entity type: Cannot bind 'httpContextAccessor' in 'User(IHttpContextAccessor httpContextAccessor, IMemoryCache memoryCache)' Note that only mapped properties can be bound to constructor parameters. Navigations to related entities, including references to owned types, cannot be bound.' im getting this error
29 replies
CC#
Created by 👻 Elektrikli Erol👻 on 4/4/2023 in #help
❔ ASP.NET to .net Core
static public List<User> GetList(int pageSize, int currentPage, out int totalCount)
{
using (EntityDBContext db = new EntityDBContext())
{
var data = (from o in db.Users orderby o.FirstName, o.LastName where o.IsDeleted == false select o);
totalCount = data.Count();
return data.Skip(pageSize * (currentPage - 1)).Take(pageSize).ToList();
}
}
static public List<User> GetList(int pageSize, int currentPage, out int totalCount)
{
using (EntityDBContext db = new EntityDBContext())
{
var data = (from o in db.Users orderby o.FirstName, o.LastName where o.IsDeleted == false select o);
totalCount = data.Count();
return data.Skip(pageSize * (currentPage - 1)).Take(pageSize).ToList();
}
}
29 replies
CC#
Created by 👻 Elektrikli Erol👻 on 4/4/2023 in #help
❔ ASP.NET to .net Core
public static User CurrentUser
{
get
{
var ck = HttpContext.Current.Request.Cookies[TOKEN_COOKIE_NAME];
Guid token;
if (ck != null && Guid.TryParse(ck.Value, out token))
{
var key = "BlueCMS_User_" + token;
if (HttpContext.Current.Cache[key] == null)
{
var user = User.GetByToken(token);
if (user != null)
{
HttpContext.Current.Cache.Add(key, user, null, System.Web.Caching.Cache.NoAbsoluteExpiration, TimeSpan.FromMinutes(15), System.Web.Caching.CacheItemPriority.Default, null);
}
else
{
RemoveToken();
}
}
return HttpContext.Current.Cache[key] as User;
}
return null;
}
set
{
var ck = HttpContext.Current.Request.Cookies[TOKEN_COOKIE_NAME];
Guid token;
if (ck != null && Guid.TryParse(ck.Value, out token))
{
var key = "BlueCMS_User_" + token;
HttpContext.Current.Cache[key] = value;
}
}
}
public static User CurrentUser
{
get
{
var ck = HttpContext.Current.Request.Cookies[TOKEN_COOKIE_NAME];
Guid token;
if (ck != null && Guid.TryParse(ck.Value, out token))
{
var key = "BlueCMS_User_" + token;
if (HttpContext.Current.Cache[key] == null)
{
var user = User.GetByToken(token);
if (user != null)
{
HttpContext.Current.Cache.Add(key, user, null, System.Web.Caching.Cache.NoAbsoluteExpiration, TimeSpan.FromMinutes(15), System.Web.Caching.CacheItemPriority.Default, null);
}
else
{
RemoveToken();
}
}
return HttpContext.Current.Cache[key] as User;
}
return null;
}
set
{
var ck = HttpContext.Current.Request.Cookies[TOKEN_COOKIE_NAME];
Guid token;
if (ck != null && Guid.TryParse(ck.Value, out token))
{
var key = "BlueCMS_User_" + token;
HttpContext.Current.Cache[key] = value;
}
}
}
29 replies
CC#
Created by 👻 Elektrikli Erol👻 on 4/4/2023 in #help
❔ ASP.NET to .net Core
29 replies
CC#
Created by 👻 Elektrikli Erol👻 on 4/4/2023 in #help
❔ ASP.NET to .net Core
is there anyway i can use HttpContext directly without using constructor like this ? private readonly HttpContext _httpContext; public User(IHttpContextAccessor httpContextAccessor, IMemoryCache memoryCache) { _httpContext = httpContextAccessor.HttpContext; _cache = memoryCache; }
29 replies