我在MVC3中遇到cookie问题.我想创建一个cookie,用于存储用户是否登录的信息.我之前从未使用过cookie,也不知道做什么是正确的方法,我是MVC3的新手.请问,有人可以告诉我,我用来存储cookie的方法是否合适,或者存在安全风险(密码是否加密)?如果cookie设置正确,我如何在其他视图中使用它们来检查用户是否已登录并为他设置会话?如果我用来登录用户的方法是错误的,请告诉我.
public ActionResult Login(string name, string hash, string keepLogged)
{
if (string.IsNullOrWhiteSpace(hash))
{
Random random = new Random();
byte[] randomData = new byte[sizeof(long)];
random.NextBytes(randomData);
string newNonce = BitConverter.ToUInt64(randomData, 0).ToString("X16");
Session["Nonce"] = newNonce;
return View(model: newNonce);
}
User user = model.Users.Where(x => x.Name == name).FirstOrDefault();
string nonce = Session["Nonce"] as string;
if (user == null || string.IsNullOrWhiteSpace(nonce))
{
return RedirectToAction("Login", "Users");
}
string computedHash;
using (SHA256 sha256 = SHA256.Create())
{
byte[] hashInput = Encoding.ASCII.GetBytes(user.Password + nonce);
byte[] hashData = sha256.ComputeHash(hashInput);
StringBuilder …Run Code Online (Sandbox Code Playgroud) 我正在寻找一种如何格式化文本的alertBody方法UILocalNotification.我注意到例如邮件应用程序设置了主题的第一行,第二行和第三行是电子邮件正文的预览.如果主题超过1行,则会被截断.这适用于动态字体,因此无论在辅助功能中设置了什么文本大小.我试图取得相同的结果,但没有成功.
我尝试了什么
sizeWithAttributes同时使用preferedFontForTextStyle所有这些解决方案部分工作,但对于某些文本大小/设备将失败
我正在寻找的方法是获取锁定屏幕的通知字体名称,大小,字距调整或任何其他必要的参数,以便能够UILocalNotification.alertBody在任何具有任何文本大小辅助功能设置的iOS设备上正确设置为1行文本.
我知道不同iOS版本的这些属性可能会有所不同,但iOS8对我来说已经足够了.
谢谢
我试图找到问题的答案,但我被困了.我有数组的集合,需要删除一些属性相同的记录.
示例:我有属性 - BeginTime,EndTime,Date,Price.
07:00, 11:00, 2011-11-14, 90
08:00, 12:00, 2011-11-14, 110
07:00, 11:00, 2011-11-15, 120
07:00, 11:00, 2011-11-14, 50
Run Code Online (Sandbox Code Playgroud)
我想删除BeginTime,EndTime和Date相同且Price不是最低的记录.在此示例中,删除的记录将是第一个.
感谢您的任何帮助或建议
我刚刚推出了我的第一个MVC3应用程序,除了cookie授权外,一切正常.当用户访问我的站点并登录时,我使用有关该用户的数据设置.ASPAUTH cookie.它运作良好,直到一段时间过去.然后我必须再次登录,即使cookie在浏览器中,我可以看到过期设置为一年后.它在我的localhost上工作正常.在我看来,它不是将我的信息设置为cookie,而是以某种方式在会话中,但即使我在一小时内重新启动计算机,我仍然登录.但如果我不在1小时内访问网络,那么我退出了.
谢谢你的帮助.
FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(
1,
requestedUser.Name,
DateTime.Now,
DateTime.Now.AddYears(1),
true,
string.Format("{0};{1};{2}", requestedUser.IDUser.ToString(), requestedUser.IsAdmin.ToString(), profilePicture));
string encryptedTicket = FormsAuthentication.Encrypt(ticket);
HttpCookie cookie = new HttpCookie(FormsAuthentication.FormsCookieName, encryptedTicket);
cookie.Expires = keepLogged == "keepLogged" ? DateTime.Now.AddYears(1) : DateTime.Now.AddHours(1);
this.Response.Cookies.Add(cookie);
return RedirectToAction("Index", "Posts");
Run Code Online (Sandbox Code Playgroud)