【发布时间】:2015-12-04 19:46:39
【问题描述】:
我目前为我的 MVC 应用程序实现了一些“检查器”。
到目前为止,这是我所拥有的,
- 授权(表格)
- 身份验证(自定义 RoleProvider)
- 操作过滤器(以确保用户不会输入任何虚假的身份证号码或尝试通过编辑
GETurl 来访问其他人的数据。
我有几个关于 ASP MVC 上 cache 最佳实践的问题。
这是我的登录实现:
[HttpGet]
[ActionName("login")]
public ActionResult login_load()
{
return View();
}
[HttpPost]
[ActionName("login")]
public ActionResult login_post(string uname,string pword)
{
using (EmployeeContext emp = new EmployeeContext())
{
//h student log = new student();
int success = emp.login.Where(x => x.username == uname && x.password == pword).Count();
if (success == 1)
{
int id = (from logs in emp.login
join rol in emp.roles on logs.role equals rol.id
where logs.username == uname
select logs.id).First();
FormsAuthentication.SetAuthCookie(uname, false);
HttpRuntime.Cache.Insert("id", id);
return RedirectToAction("Details", "Enrollment", new { id = id});
}
return View();
}
}
(我计划尽快实施 H&S)
无论如何,到目前为止,这是我的担忧:
- 出于安全考虑,是否可以将
id之类的内容存储在缓存中?或者如果我使用sessions会更好? -
假设我成功登录,我添加了另一行代码:
HttpRuntime.Cache.Insert("id", id);它是要编辑我以前的记录还是要添加另一个条目? 我从我的自定义
RoleProvider、HttpRuntime.Cache.Insert(cacheKey, roles, null, DateTime.Now.AddMinutes(_cacheTimeoutInMinute), Cache.NoSlidingExpiration);中获得了这段代码,我相信每次我询问具有[Authorize(Role="users")]保护的控制器时,它们都会被“解雇”。那么它是创建一个新条目还是编辑以前/现有的条目? - 我是否应该担心在用户决定退出后立即删除/清除我的
cache?我的角色提供者超时当前设置为20 minutes
我需要id,因为除了用户名之外,它是我的唯一标识符,我用它来比较用户尝试访问的任何 ID。
我正在考虑是否可以编辑缓存并将其用于我的应用程序。
【问题讨论】:
标签: asp.net asp.net-mvc asp.net-mvc-4 caching