简体   繁体   English

使用ASP.NET Auth和带有Silverlight的DomainService保护WCF服务

[英]Securing WCF services using ASP.NET Auth and a DomainService with Silverlight

I have the basic ASP.NET authentication domain service running in my Silverlight app (the one that comes with the VS2010 Silverlight Business template). 我在Silverlight应用程序(VS2010 Silverlight Business模板随附的服务)中运行了基本的ASP.NET身份验证域服务。

How can I use the authentication that this grants to secure methods exposed by standard WCF services (also hosted in the same app in IIS)? 如何使用授予的身份验证来保护标准WCF服务(也托管在IIS的同一应用程序中)公开的方法?

Ok, so this is how you do it, the standard WCF service needs a couple of attributes, and you need to assign the Thread.CurrentPrincipal : 好的,这就是您的操作方式,标准WCF服务需要几个属性,并且需要分配Thread.CurrentPrincipal

[ServiceContract(Namespace = "")]
[SilverlightFaultBehavior]
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
public class Service1
{
    public Service1()
    {
        Thread.CurrentPrincipal = HttpContext.Current.User;
    }

    [OperationContract]
    [PrincipalPermission(SecurityAction.Demand, Role = "Registered Users")]
    public string DoSomeWork()
    {
        return "working";
    }
}

A good place to start is here: Security for WCF RIA Services . 一个不错的起点是: WCF RIA服务的安全性 What you're looking for is the RequiresAuthentication attribute. 您正在寻找的是RequiresAuthentication属性。

[RequiresAuthentication]
public Foo SomeMethodCall(object parameter1)
{
    return service.GetResult(parameter1)
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM