views:

130

answers:

2

Hi,

I have a silverlight application that calls my wcf services so its a basichttpbinding. and we use forms authentication. I want to do a authentication check for every call that I receive except for the "AuthenticationService" (as this is the method which will do the basic authentication for login) so after user logs in and tries to call other services then I want this authentication check to be performed so that only authenticated users will be granted access to them. Is there is any best way to implement this... ???

After searching through various blogs, I came to know that we can use HttpContext.Current....IsAuthenticated property to check if user is authenticated or not. But my question is how secure and valid is HttpContext? Can we rely on that? or should we be using OperationContext? (and yes aspnetcompatability is set to true).

Please suggest!!

Thanks in advance
Sai

A: 

Here are some articles that may help:

http://msdn.microsoft.com/en-us/library/dd560702%28VS.95%29.aspx http://silverlightuk.blogspot.com/2008/03/silverlight-wcf-and-aspnet.html http://smehrozalam.wordpress.com/2009/01/07/securing-silverlight-application-and-wcf-service-using-aspnet-authentication-techniques/

Short answer is you can use the asp.net controls to do authorization, or use HttpContext.Current directly (as long as AspNetCompatMode is enabled).

alexdej
Thank you for your reply... So I will go on with HttpContext then..
Sai
+1  A: 

If you're hosting your WCF services in the ASP.NET runtime (i.e. <serviceHostingEnvironment aspNetCompatibilityEnabled="true" />) then you should absolutely be able to rely on ASP.NET's security system.

Check out this answer I gave to another question on how to leverage ASP.NET security for ASMX services. The same approach can be used to secure a WCF service as long as you're enabling ASP.NET as your service hosting environment.

Drew Marsh
Thank you for your reply... I did not understand how to apply Step#3 that you mentioned in the link for wcf service...if I apply authorization(<deny users="?">) then I cannot find even find the my wcf service using url - "http://localhost/myservice.svc" gives me error...http 404 resource not found...then I cannot add my service to other projects.. how can I apply authorization?
Sai
You should be getting a 40*1* if anything. However, you said you have forms authentication enabled so the forms auth module should be capturing that and doing it's redirect to the login form. I'm assuming this service is some kind of AJAX bridge the way you've described it, otherwise forms authentication makes no sense.
Drew Marsh