简体   繁体   English

使用razor引擎管理asp.net mvc4中的会话

[英]Managing sessions in asp.net mvc4 with razor engine

I have an asp.net application mvc4. 我有一个asp.net应用程序mvc4。 i have an authentification view : the user login as a normal user or an administrator. 我有一个身份验证视图:用户以普通用户或管理员身份登录。

[OutputCache(NoStore = true, Duration = 0)]
        public ActionResult Index()
        {
            if (Upload.Models.CompteModels.Connected)
            {
                Upload.Models.ClientModels model1 = new Models.ClientModels();
                List<ClientModels> client = model1.Client_List();

                Upload.Models.AkeoModels model2 = new Models.AkeoModels();
                List<AkeoModels> akeo = model2.Akeo_List();



                MemberModels m = new MemberModels();
                m.AkeoModels = model2.Akeo_List();
                m.ClientModels = model1.Client_List();

        return View(m);
     }
   else return RedirectToAction("Login", "Account");

 }

if i launch the application in a browser for example chrome and login to the admin account. 如果我在浏览器中启动应用程序,例如chrome并登录管理员帐户。 Then i drag and drop the url of the admin page to another browser like opera it's works and displays the admin's page despite it's a new session. 然后我将管理页面的URL拖放到另一个浏览器,如opera它的工作,并显示管理员的页面,尽管它是一个新的会话。

Why this happens? 为什么会这样? how can i manage the sessions to avoid this problem? 如何管理会话以避免此问题?

My guess is that you have not locked down authorization for the admin's page. 我的猜测是你没有锁定管理员页面的授权。 You need something that checks to determine if the current user is authenticated, in the correct role, etc. What are you using for authentication and authorization? 您需要检查以确定当前用户是否经过身份验证,角色是否正确等等。您使用什么进行身份验证和授权?

The Authorize attribute exists specifically for the purpose of locking down pages to authenticated users. Authorize属性专门用于将页面锁定到经过身份验证的用户。 Additionally, you can specify what roles to allow. 此外,您可以指定允许的角色。

You are using the Upload.Models.CompteModels.Connected to determining if to redirect to the login page. 您正在使用Upload.Models.CompteModels.Connected来确定是否重定向到登录页面。

It appears that you are caching this value on the server, so regardless of who accesses the page, if the value is true, they will get the view. 您似乎在服务器上缓存此值,因此无论谁访问该页面,如果值为true,它们将获得该视图。

I recommend you use the Authorize attribute to protect the page: 我建议您使用Authorize属性来保护页面:

[Authorize]
public ActionResult Index()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM