Silverlight Ria 身份验证 - 在使用 DomainContext 之前检查身份验证
我已经开始创建一个标准的 Silverlight/RIA/EF 应用程序,它可以按预期立即运行。
我想将整个 DomainService 限制为仅允许经过身份验证的用户,因为应用程序最终将驻留在公共互联网上,并且所有数据访问都需要经过用户身份验证。
我遇到的问题是,我无法在 Silverlight 应用程序中使用自动生成的 DomainContext 类,除非我将其所有 Load 方法包装在一个自定义类中,该类在尝试检索数据之前验证用户的身份验证状态 - 这看起来像是一个漫长而乏味的编码任务。
当然一定有一个我错过的简单解决方案?
这在 ASP.NET 中很容易,因为当您丢失(或从未获得)身份验证时,您会被重定向到登录页面(如 web.config 中配置的那样)。
我真的很惊讶 Silverlight 中没有类似的机制,因为它似乎是标准的业务应用程序要求。
I have the beginnings of a standard Silverlight/ RIA/ EF application that is just working straight away as expected.
I wanted to restrict my entire DomainService to only authenticated users, as the application will eventually live on the public internet, and all data access needs to be user authenticated.
The problem I have, is that I cannot use the auto-generated DomainContext class in my Silverlight app unless I wrap all of its Load methods inside a custom class that verifies the authentication status of the user before attempting to retrieve data - which seems like a long and tedious coding task.
Surely there must be a simple solution that Ive missed ?
This stuff was easy in ASP.NET because the moment you lost (or never had) authentication you were redirected to a login page (as configured in web.config).
Im really suprised theres no similar mechanism in Silverlight, as it seems to be to be a standard business application requirement.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在您的 DomainService 中要求身份验证很容易。只需将 [RequiresAuthentication] 或 [RequiresRole] 属性添加到类(适用于所有操作)或您想要授权的操作即可。您可能会发现这些链接很有帮助。
如何:在 RIA 服务中启用身份验证
RequiresAuthenticationAttribute< /a>
Requiring authentication in your DomainService is easy. Just add a [RequiresAuthentication] or [RequiresRole] attribute to either the class (applies to all operations) or operation you want to authorize. You might find these links helpful.
How to: Enable Authentication in RIA Services
RequiresAuthenticationAttribute
我不是 100% 先生,如果这是您想要的答案,并且这样做是一个很好的做法,但您可以实现一个消息检查器来检查用户是否通过了身份验证,如下所示:
I am not 100% sire if this is the answer you want and if it's a good practice to do it like this but you could implement a message inspector that inspects whether the user is authenticated like this: