views:

289

answers:

1

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.

+1  A: 

Hi , 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

Phani Raj
I ended up going a different direction, but I think this was the link that I was missing. Thanks.
ee