I just started using WCF Services with ASP.NET AJAX. I instantiate my WCF service from Javascript and then pass string variables as arguments to my WCF Service method (with an OperationContract signature). I then return a .NET object (defined with a DataContract) which is bound to my custom Javascript class. I'm having trouble authenticating based on the user logged into my web session. However, the WCF web service is a completely different service with no context to the HttpContext.Current object. What is the most secure way to get access to that object?
相关问题
- How to make a .svc file write to asp.net Trace.axd
- WCF Service Using Client Certificates Requires Ano
- WCF error with net.tcp "The service endpoint faile
- Singleton with AsyncLocal vs Scope Service
- WCF Service Reference Support Files Not Updating
相关文章
- Service层和Dao层一定要对应吗?
- k8s 访问Pod 时好时坏
- WCF发布Windows服务 POST方式报错 GET方式没有问题 应该怎么解决?
- XCopy or MOVE do not work when a WCF Service runs
- Async task does not work properly (doInBackground
- Convert HttpContent into byte[]
- Could not find default endpoint element that refer
- The 'DbProviderFactories' section can only
You do not have a HttpContext by default but you have many of the same objects present in the OperationContext (which is always present) or the WebOperationContext (which is only available for certain bindings.
You can access the OperationContext or WebOperationContext by using the static
.Current
property like so:WebOperationContext.Current
You can get access to
HttpContext.Current
by enabling AspNetCompatibility, preferably via configuration:That in turn allows you to get access to the current user:
HttpContext.Current.User
- which is what you're after, right?You can even enforce AspNetCompatibility by decorating your service class with an additional attribute:
(In the
System.ServiceModel.Activation
namespace.) If that attribute is in place, your service will fail to start unless AspNetCompatibility is enabled!In case you don't want to change Web.config or you cannot change it: