I am trying to do this with an httpRequestBegin pipeline processor, but I don't seem to be able to access the user's IP address from the given HttpRequestArgs parameter.
When I implement a class that has this method
public void Process(HttpRequestArgs args) {
string ipAddress = args.Context.Request.UserHostAddress; // Not working
string state = GetState(ipAddress); // already implemented elsewhere
RedirectUserByState(state); // already implemented elsewhere
}
I thought that this might hold the user's IP address
args.Context.Request.UserHostAddress
but it causes this error instead (stack trace says it originates from the Process method):
System.Web.HttpException: Request is not available in this context
Any ideas? Thanks!
Edit, this is in Sitecore 6.1 and in the web.config at
<pipelines>
<!--...-->
<httpRequestBegin>
<!--...-->
<processor type="Sitecore.Pipelines.HttpRequest.ItemResolver, Sitecore.Kernel"/>
<processor type="MySolution.Redirector, MySolution"/>
<processor type="Sitecore.Pipelines.HttpRequest.LayoutResolver, Sitecore.Kernel"/>
<!--...-->
</httpRequestBegin>
<!--...-->
</pipelines>
This server might be behind a load balancer.
Edit 2: It looks like I was trying to access both of these inside the Process() function and that is what was causing the error:
Sitecore.Context.Request
Sitecore.Context.Response