YodasMyDad / mvcforum

MVCForum is a fully featured responsive and themeable ASP.NET MVC 5 discussion board/forum and features similar to StackOverFlow
MIT License
553 stars 406 forks source link

Add IP tracking to Activity table #134

Closed blandyuk closed 6 years ago

blandyuk commented 7 years ago

As admins, we need to have the ability to track IP addresses and the activity tracker is the best place to do this. Can you please add support for it? Should be simple enough. Also, make sure you accommodate for the likes of Cloudflare / Incapsula. This means the Request.UserHostAddress will not be correct as it will be Cloudflare's IP instead.

To do this, CF adds a Header with the originating IP as show below:

string ip = Request.Headers["CF-Connecting-IP"] ?? Request.UserHostAddress;

This will be very helpful if it can be added. Maybe have a global Setting which can be configured to look for a specific Header name incase users use Incapsula or some other similar service?

blandyuk commented 7 years ago

Update on this. Noticed there is an [IpAddress] field on the [Post] table but, as part of adding a new topic, the code did not record the users IP. Replys / posts to the topic do save the IP.

I have added "post.IpAddress = StringUtils.GetUsersIpAddress();" to the "PostService" "public Post Add(Post post)" function.

I have also added CloudFlare support to the "StringUtils" "public static string GetUsersIpAddress()" function.