MVC处理一个CorpId该网站 [英] MVC Handling a CorpId for the site

查看:114
本文介绍了MVC处理一个CorpId该网站的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不知道我处理这个正确的方式,但由于我运行到的问题,我想我没有。

I'm not sure I'm handling this the right way, but since I'm running into issues, I assume I'm not.

我必须加载登录屏幕时发出的公司标识。

I have to have a corporation id sent in when loading the login screen.

是这样的:

public ActionResult LogOn(string id)
{
  var sb = new StringBuilder();
  sb.AppendLine(string.Format("CorpID: {0}", id));

  if(ViewBag.CorpID != null)
    sb.AppendLine(string.Format("ViewBag.CorpID: {0}", ViewBag.CorpID));

  Guid corpIdGuid;
  if (!Guid.TryParse(id, out corpIdGuid) && string.IsNullOrEmpty(ViewBag.CorpID))
    return null;

  // the id passed in will take presidence over the 
  // viewbag unless it is blank then we use viewbag
  // one way or the other viewbag.corpid should not
  // be blank
  if(!string.IsNullOrEmpty(id))
    ViewBag.CorpID = id;

  // Session["CorpId"] = id;
  //Not a junk guid.. continue.
  return View();
}

我需要这个建立什么公司,我们将在本届会议期间的工作。

I need this to establish what company we will be working with during this session.

我遇到的问题是如果cookie超时发生时,它被设置为10分钟,它引导他们回到这个登录,我没有corpid了。

The problem I am running into, is when the cookie timeout occurs, which is set to 10 minutes, it directs them back to this login and I have no corpid anymore.

我试过 viewbag 键,它被复位。

我试过一个cookie,但由于它到期,数据不再存在。

I tried a cookie, but since it expires, the data is no longer there.

我尝试了配置文件管理器,但因为它们是记录它,这使我回罢了。

I tried a Profile Manager but since they are logged it, that puts me back to nothing.

我如何保持这种 CorpId 当用户已超时后,再放回到登录屏幕上?我需要这个信息,每个屏幕我有也。

How do I maintain this CorpId when the user has timed out and put back on the login screen? I need this information for each screen I have also.

任何投入将大大AP preciated!

Any input would be greatly appreciated!

推荐答案

您需要创建一个单独的cookie标识的公司ID 不与用户的会话过期。 会话[CorpId] 将与用户会话过期,将无法正常工作。

You need to create a separate cookie that identifies the Corporate ID that doesn't expire with user's session. Session["CorpId"] will expire with the user session and won't work.

var corpCookie = new HttpCookie("CorpID", id);
corpCookie.Expires = DateTime.Now.AddDays(30.0);
HttpContext.Current.Response.Cookies.Set(corpCookie);

每次用户登录时,你可以更新过期,使其滑动过期。要检索cookie值,使用以下命令:

Each time the user logs in, you could update the expiry to make it a sliding expiration. To retrieve the cookie value, use the following:

var corpID = HttpContext.Current.Request.Cookies.Get("CorpID").Value;

这篇关于MVC处理一个CorpId该网站的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆