Car*_*nta 1 asp.net asp.net-mvc caching asp.net-mvc-4
我目前为我的MVC应用程序实现了一些"检查器".
到目前为止,这是我所拥有的,
GET
URL来访问其他人的数据.cache
关于ASP MVC 的最佳实践,我有几个问题.
这是我的登录实现:
[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();
}
}
Run Code Online (Sandbox Code Playgroud)
(我计划尽快实施H&S)
无论如何,到目前为止我的担忧是:
id
缓存中的内容存储起来会不会很好?或者如果我使用它会更好sessions
?假设我已成功登录,并添加了此代码的另一行:
HttpRuntime.Cache.Insert("id", id);
它是要编辑我以前的记录还是要添加另一个条目?我从我的Custom获得了这个代码RoleProvider
,HttpRuntime.Cache.Insert(cacheKey, roles, null, DateTime.Now.AddMinutes(_cacheTimeoutInMinute), Cache.NoSlidingExpiration);
并且我相信每次我问一个具有保护功能的控制器时它们都会被"解雇" [Authorize(Role="users")]
.那么它是创建一个新条目还是编辑上一个/现有条目?
cache
用户决定退出,我是否应该担心删除/清除我?我的角色提供程序超时当前设置为20 minutes
我需要的是id
因为除了用户名之外,它是我的唯一标识符,我用它来比较用户试图访问的任何ID.
我在想是否可以编辑缓存并将其用于我的应用程序.
不要担心存储ID,你需要返回并重构使用MVC框中的内置标识内容.看看你的代码,我只能假设这个系统会以纯文本形式存储密码.您不会通过任何此类系统的合规性.
当谈到"这是安全的"时的经验法则是不要自己写.找到经过验证的产品并使用它.
如果由于某种原因,随MVC提供的内置身份系统无法满足您的要求,请查看以下内容:https://github.com/brockallen/BrockAllen.MembershipReboot
仅供参考:身份系统是将人员记入,记录和管理登录用户的服务.请随意访问以了解有关MVC内置系统的更多信息:http://www.asp.net/identity/overview/getting-started/introduction-to-aspnet-identity
归档时间: |
|
查看次数: |
746 次 |
最近记录: |