New Posts New Posts RSS Feed: HttpContext in SaveInterceptor
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

HttpContext in SaveInterceptor

 Post Reply Post Reply
Author
gregweb View Drop Down
DevForce MVP
DevForce MVP
Avatar

Joined: 10-Sep-2009
Location: Clearwater, Fl
Posts: 253
Post Options Post Options   Quote gregweb Quote  Post ReplyReply Direct Link To This Post Topic: HttpContext in SaveInterceptor
    Posted: 23-Feb-2013 at 7:06pm
Thanks very much, works great.

Greg
Back to Top
kimj View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 09-May-2007
Posts: 1391
Post Options Post Options   Quote kimj Quote  Post ReplyReply Direct Link To This Post Posted: 23-Feb-2013 at 5:51pm
The EntityServerSaveInterceptor is running within the context of an EntityServer WCF service, so to access the HttpContext you must set the aspNetCompatibilityEnabled flag in the web.config. 
 
<system.serviceModel>
   <serviceHostingEnvironment aspNetCompatibilityEnabled="true" />
</system.serviceModel>
 
If you do this, also be sure to set the targetFramework on the httpRuntime element:
 
<system.web>
 <httpRuntime targetFramework="4.5"/>
</system.web>
 
Alternately, you can grab the IP address directly from WCF, like this:
 
var ctx = OperationContext.Current;
var endpoint = ctx.IncomingMessageProperties[RemoteEndpointMessageProperty.Name] as RemoteEndpointMessageProperty;
string ip = endpoint.Address;
 
You'll need to add a reference to the System.ServiceModel assembly to use these types.

   

 

Back to Top
gregweb View Drop Down
DevForce MVP
DevForce MVP
Avatar

Joined: 10-Sep-2009
Location: Clearwater, Fl
Posts: 253
Post Options Post Options   Quote gregweb Quote  Post ReplyReply Direct Link To This Post Posted: 23-Feb-2013 at 2:00pm
Is it possible to access the HttpContext.Current from the SaveInterceptor?

I have tried, but it is always null.

What I am trying to do is get the IP address of the request so I can log it.

No authentication is being used - it's just for logging web site analytics.

Greg
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down