Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WCF WebGet Capture HTTP Referrer?

I have a self-hosted WCF app using Basic HTTP Binding, no SSL, running in a console app on .NET Framework 4.0.

I have a WebGet Attribute on a method to which returns a human-readable string as a "smoke test".

If I had an ASP.NET webforms page, I would use Request.UrlReferrer or ServerVariables("HTTP_REFERER") to see if the client volunteers their redirect information.

How can I do that with WCF?

Thanks.

like image 485
Snowy Avatar asked Mar 31 '12 03:03

Snowy


1 Answers

If you're using BasicHttpBinding, the WebGet attribute is probably being ignored (it's used for endpoints which use the webHttpBinding and the WebHttpBehavior).

If you're using a "web" endpoint (WebHttpBinding / WebHttpBehavior), you can use the WebOperationContext.Current.IncomingRequest.Headers[HttpRequestHeader.Referer]. If you don't have a reference to System.ServiceModel.Web.dll, you can also use the HttpRequestMessageProperty from the OperationContext:

HttpRequestMessageProperty prop;
prop = (HttpRequestMessageProperty)OperationContext.Current.IncomingMessageProperties[HttpRequestMessageProperty.Name];
var referer = prop.Headers[HttpRequestHeader.Referer]
like image 140
carlosfigueira Avatar answered Sep 30 '22 02:09

carlosfigueira