需要有关 WCF 数据服务中动态连接字符串的帮助...在 OnRequest() 之前调用 CreateDataSource()?
我有一个基于 Linq2Sql 数据提供程序构建的可用 WCF 数据服务。到目前为止,情况看起来不错。
访问该服务的客户端应用程序接受我在服务器上进行身份验证的用户和密码。然而,在服务器端,每个客户端的数据存储在单独的特定于客户端的数据库中。因此,我需要能够在用户对自己进行身份验证/识别后更改数据提供者的连接字符串。
我重写了数据上下文的 CreateDataSource() 方法(这似乎使我能够动态更改连接字符串,这很好)。但是,在调试过程中,我看到 CreateDataSource() 在 OnRequest() 之前触发... OnRequest() 是我处理用户身份验证的地方,所以我不知道他们是谁,也不知道他们在 CreateDataSource 时是否获得授权() 起火。
是否有另一种方法可以处理动态连接字符串问题,而无需在请求处理程序之前调用 CreateDataSource() ?或者,不太理想的是,有没有办法延迟或触发服务/数据提供者在身份验证后再次调用 CreateDataSource(),以便我可以知道用户是谁,并构造正确的连接字符串?
谢谢!
I have a working WCF Data Service built on a Linq2Sql data provider. Things are looking good so far.
The client app that hits the service accepts a user and password which I authenticate at the server. However, on the server-side the data for each client is stored in a separate client-specific database. So, I need to be able to change the connection string for the data provider after the user has authenticated/identified themselves.
I overrode the data context's CreateDataSource() method (which appears to give me the ability to change the connection string dynamically, which is good). However, during debugging, I see that CreateDataSource() fires before OnRequest()... OnRequest() is where I handle user authentication, so I don't know who they are yet or whether they're authorized at the time that CreateDataSource() fires.
Is there another way to handle the dynamic connection string issue, without having CreateDataSource() called before my request handler? Or, less optimally, is there a way to delay, or trigger the service/data provider to call CreateDataSource() again after authentication, so I can tell who the user is, and construct the proper connection string?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以在 CreateDataSource 方法中进行身份验证吗?首先进行身份验证,然后使用适当的连接字符串相应地创建数据源。
每次都会调用 CreateDataSource 方法来创建数据源的新实例。
谢谢
普拉蒂克
Is there a reason why you can do the authentication in CreateDataSource method - First do the authentication, and then accordingly create the datasource with the appropriate connection string.
CreateDataSource method is called everytime to create the new instance of your data source.
Thanks
Pratik