ASP.NET 会员资格 跨不同层发送用户名
我有 3 层(UI、BLL、DAL),这些 BLL 和 DAL 驻留在外部 WS 上,显然我的会员用户在 UI 层上工作。
所以...我试图在我的 Bussines 表中存储不同任务的用户名(如 CRUD)
- 插入注册表(用户名:nicolas)
- 删除注册表(用户名:peter) 等等...
最简单的方法是在所有方法上发送用户名并存储在不同的表中。但如果你有很多业务表,这个想法是不可扩展的并且非常脏。
有人知道另一种方法可以做到这一点吗?我读到了有关编写自定义会员资格提供程序以将不同用户存储在缓存中并从中检索的内容。但我不知道这是否是最好的解决方法。
有什么想法吗?
I have 3-tiers (UI, BLL, DAL), those BLL and DAL reside on external WS, obviously my membership user works on the UI tier.
So... I was trying to store in my Bussines tables the username for the differents tasks (like a CRUD)
- Insert registry (username: nicolas)
- Delete registry (username: peter)
etc...
The simplest way is send the username on ALL methods and store in the differents tables. But this idea is not scalable and very dirty if you have a lot of bussines tables.
Any know another way to do this? I read about writing a custom membership provider to store the differents user on cache and retrieve from this. But i don't know if this is the best workaround.
Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
ASP.NET 的自定义控件依赖于 System.Web 中的成员资格库(更具体地说,System.Web.Security)。只要您使用这些控件(例如
控件),您就已经依赖于 System.Web。在这种情况下,应用程序的任何层都可以执行类似以下操作来检索当前用户:然后使用
user.UserName
检索用户的用户名。已更新以反映层托管在单独服务器上的理解。
我将向 BLL 添加 StartSession() 方法,该方法将用户名作为参数,并返回字符串会话 ID。服务器上的 BLL 生成会话 ID(可能使用 Guid)并使用 BLL 端缓存来保存用户名。然后在客户端设置一个包含会话 ID 的 cookie。它将与网络请求一起提交。 (根据您提交 Web 请求的方式,您可能必须使用 javascript 设置 cookie 值。)
这样您就不必修改方法的签名,但仍然可以通过使用从 BLL 获取用户名缓存。您必须确保您的登录页面调用 GetSession() 方法,并在提交更多请求之前设置会话 cookie。
The custom controls for ASP.NET rely on the Membership library in System.Web (more specifically, System.Web.Security). As long as you are using those controls (for example, the
<asp:Login>
control) you already have a dependency on System.Web. In that case, any layer of your application can do something like this to retrieve the current user:Then use
user.UserName
to retrieve the user's username.UPDATED to reflect the understanding that the layers are hosted on separate servers.
I would add a StartSession() method to the BLL that takes the username as a parameter, and returns a string session ID. The BLL on the server generates the session ID (perhaps using a Guid) and uses the BLL-side cache to save the username. Then on the client side, set a cookie that contains the session ID. It will get submitted along with the web request. (Depending on how you submit the web request, you may have to set the cookie value with javascript.)
That way you don't have to modify the signature of your methods, but can still get ahold of the username from the BLL by using the cache. You will have to make sure your login page calls the GetSession() method, and sets the session cookie before submitting more requests.
除非您使用 BLL 和 DLL 中的服务,否则有什么意义呢?除了通过 UI 之外无法访问这些服务。
Unless you are using services in the BLL and DLL then what is the point, there is no access to these except through the UI.