托管 ADO.NET DataService时在 WCF WebServiceHost 中,如何访问请求中提供的凭据?

发布于 2024-08-10 22:23:16 字数 851 浏览 1 评论 0原文

如果我有这样的类型:

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

尝蛊 2024-08-17 22:23:16

要访问 DataService 中当前登录用户的凭据,您需要:
a) 设置数据服务以能够访问当前的 Web Http 上下文

使用 System.ServiceModel.Activation;
/// <摘要>
/// 要求 WCF 主机设置对当前执行请求的 WebHttpContext 的访问权限。
/// 这里有更多详细信息:http://msdn.microsoft.com/en-us/library/aa702682.aspx
/// 
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Required)]
公共类 ContextService : DataService;

b) 通过 HttpContext.Current.User 属性访问当前用户的详细信息

if(System.Web.HttpContext.Current.User.Identity.Name ==某人)
{
//返回一些东西
}
别的
{
//返回其他内容
}

一些有用的链接
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

using System.ServiceModel.Activation;
/// <summary>
/// Require that the WCF host setup access to the WebHttpContext of the currently executing request.
/// More details here : http://msdn.microsoft.com/en-us/library/aa702682.aspx
/// </summary>
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Required)]
public class ContextService : DataService<Context>

b) access the Current user's details via the HttpContext.Current.User property

if (System.Web.HttpContext.Current.User.Identity.Name == someone)
{
//return something
}
else
{
//return something else
}

Some useful links
HttpContext.Current.User on MSDN
Sharing state between ASP.NET and WCF

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文