托管 ADO.NET DataService时在 WCF WebServiceHost 中,如何访问请求中提供的凭据?
如果我有这样的类型:
public class Context
{
public Context()
{
}
public IQueryable<Record> Records
{
get
{
if (user == someone) //psuedocode
{
//return something
}
else
{
//return something else
}
}
}
}
我正在这样的 DataService 中托管:
WebServiceHost host = new WebServiceHost(typeof(DataService<Context>, "http://localhost:43334/");
WebHttpBinding binding = new WebHttpBinding();
ServiceEndpoint endpoint = host.AddServiceEndpoint(
typeof(System.Data.Services.IRequestHandler), binding,
"folder");
host.Open();
如何从客户端请求获取对提供的凭据的访问权限?我知道有拒绝访问的选项,但我如何实际获取提供的凭据来确定拒绝谁和/或给定用户可以访问哪些记录?我觉得这要么很简单,但我错过了一些东西,要么我找错了对象。
If I have a type like:
public class Context
{
public Context()
{
}
public IQueryable<Record> Records
{
get
{
if (user == someone) //psuedocode
{
//return something
}
else
{
//return something else
}
}
}
}
that I am hosting in a DataService like this:
WebServiceHost host = new WebServiceHost(typeof(DataService<Context>, "http://localhost:43334/");
WebHttpBinding binding = new WebHttpBinding();
ServiceEndpoint endpoint = host.AddServiceEndpoint(
typeof(System.Data.Services.IRequestHandler), binding,
"folder");
host.Open();
How does one gain access to the supplied credentials from the client-side request? I know there are options to deny access, but how do i actually get the supplied credentials to determine whom to deny and/or what Records could be accessible by a given user? I feel like this is either really easy and I am missing something, or that I am barking up the wrong tree.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
要访问 DataService 中当前登录用户的凭据,您需要:
a) 设置数据服务以能够访问当前的 Web Http 上下文
b) 通过 HttpContext.Current.User 属性访问当前用户的详细信息
一些有用的链接
MSDN 上的 HttpContext.Current.User
在 ASP.NET 和 WCF 之间共享状态
To get access to the current logged-in user's credentials in your DataService ,You will need to :
a) Setup the Data Service to be able to access the current Web Http Context
b) access the Current user's details via the HttpContext.Current.User property
Some useful links
HttpContext.Current.User on MSDN
Sharing state between ASP.NET and WCF