you haven't mention what issue you are facing. Looking at the code I believe you have to bypass the checking in case of local server. If your local server url is like this
then you can see
if (InRequest.Request.RawUrl.Split('/').Length > 3)
will yield true and process accordingly, so either you have to bypass the checking for local server or you have to handle this case. I hope this will help to solve your issue.