I am new to MVC. I am trying to create a landing page where the users may use it to open specific websites. I want to detect whether the user is accessing it through a local iPad or through a VPN or the public iPad. So I can direct them to the website using their specific address.
For example, I want to access our inventory system and on the landing page I would just click the button and direct them using their iPad.
For example I am using a local IP and that IP is 12.12.12.2 and the port number of our inventory system is 211. If I click on the button I want to be directed using that IP which will be 12.12.12.2:211 and same goes to VPN and public IP.
This is what I've tried
Controller:
public ActionResult GetIP()
{
return Json(new { ip = Request.UserHostAddress }, JsonRequestBehavior.AllowGet);
}
JS:
$("#target").click(function() {
var port = $(this).attr("data-itemId");
$.ajax({
type: "POST",
url: "/Home/GetIP/",
success: function (data) {
if (data.ip = '12.12.12.2'){ --local
window.open('//' + '12.12.12.2:' + port);
}
if (data.ip = '12.12.12.7') { --vpn
window.open('//' + '12.12.12.7:' + port);
}
if (data.ip = '123.123.123') { --public
window.open('//' + '123.123.123.54:' + port);
}
else {
alert(Error);
}
}
});
});
I was able to direct it when I was using localhost. But when I tried to publish it on our server they open all at the same time. I get three tabs with the IP addresses.
I hope someone can help. Thank you so much.