MVC个别用户帐户登录值持续存在 [英] MVC Individual User Accounts login value persisting

查看:155
本文介绍了MVC个别用户帐户登录值持续存在的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个MVC的网站使用ASP.NET身份。这个网站可用于多个客户的数据,并且每个客户是独立于另一个,没有数据要共享的。每个事务应该是在选择客户数据客户只发生。

然而,谁登录可以看到所有客户的用户,他们只是在登录时选择交易对哪个客户。

所以在登录时,他们会选择从下拉他们的客户,然后看到所有客户的项目,个人信息和独特的东西,可以为客户做。

因此​​,例如

  VAR allItems =从在那里db.Items = a.CustomerId选择客户ID一个;

此客户ID可以在登录时得到的,它的是什么用户从下拉选择。但是,我怎么坚持在整个用户的整体这个选择登录会话?我显然不希望将其保存到其不是一个永久性的选择,我想选择走了数据库的时候,他们退出,他们可以自由地选择其他客户下次登录。

另一个很酷的事情是能够覆盖get方法中的DbContext中检索匹配仅无论客户编号登录时选择的项目

 公共DbSet<项目> ItemsAll {搞定;组; }公众的IQueryable<项目>项目
{
     得到
     {
          返回ItemsAll.Where(X => x.Customer == myLoggedInCustomerChoice);
     }
}


解决方案

值添加到会话变量,对证当加载页面。

I have an MVC website that uses ASP.NET Identity. This site can be used for multiple customers data, and each customer is independent to another, no data should be shared. Each transaction should happen only on that customers data when that Customer is selected.

However, the Users who log in can see All customers, they just choose at login which customer to transact against.

So upon login, they will pick from a Dropdown their customer, and then see all that customers items, individual information, and unique things that can be done for that customer.

So for example

var allItems = from a in db.Items where a.CustomerId = customerId select a;

This customer Id can be got at login, as its what the User chose from a dropdown. However, how do I persist this choice throughout the entirety of the users log in session? I obviously don't want to save it to the database as its not a permanent choice I want the choice to be gone when they log out, with them to be free to choose another Customer next login.

Another cool thing would be able to override the get method in the DbContext to retreive only items matching whatever customer Id was selected on login

public DbSet<Item> ItemsAll { get; set; }

public IQueryable<Item> Items
{
     get
     {
          return ItemsAll.Where(x => x.Customer == myLoggedInCustomerChoice);
     }
}

解决方案

Add the value to a Session-variable, and check against it when you load pages.

这篇关于MVC个别用户帐户登录值持续存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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