43341

C# ASP.net Test if user comes from Local Network

Question:

I want to use C#/ASP.net to find out whether the user browsing the website is on the same network so that certain links are only displayed while in the office (to those who have access to them).

Anyone accessing from within the office will be doing so by going to it's local IP address (i.e. 192.168.x.x) whereas external users will be browsing to the public domain name.

All I need is some way to differentiate between the two types of user.

Answer1:

if (Request.UserHostAddress.StartsWith("192.168")) { //localuser }

Answer2:

Take a look @ Request.Url.Host - you'll be able to pluck the address from this.

Recommend

  • How to prevent cross domain issues by proxying in IIS?
  • Performance difference between accessing local and class member variables
  • Access PCF DEV from external machine on same network as host
  • Google OAuth2 for an web application hosted behind NAT (intranet server without public IP)
  • Microsoft Chart Controls for Microsoft .NET Framework 4.0
  • Is mp4 stream able with ffserver?
  • Open an application in a space using applescripts
  • How to resolve docker host names (/etc/hosts) in containers
  • css background images not always displayed
  • Should I be afraid to use UDP to make a client/server broadcast talk?
  • Python/Javascript: WYSIWYG html editor - Handle large documents fast and/or design theory
  • You tube videos are not playing
  • IE10 strips out hashtag from the URL
  • C# List of Panels
  • Synchronize windows folders
  • How to return DataSet (xsd) in WCF
  • Looking for good analogy/examples for monitor verses semaphore
  • ADO and msqli connections very slow
  • How to write order and limit within cakephp joins array
  • AJAX Html Editor Extender upload image appearing blank
  • PHP buffered output depending on server setting?
  • Custom validator control occupying space even though display set to dynamic
  • Cannot resolve symbol 'MyApi'
  • Apache 2.4 and php-fpm does not trigger apache http basic auth for php pages
  • Get object from AWS S3 as a stream
  • Window Size for Mac application
  • Cross-Platform Protobuf Serialization
  • Validaiting emails with Net.Mail MailAddress
  • Do I've to free mysql result after storing it?
  • Apache 2.4 - remove | delete | uninstall
  • Windows forms listbox.selecteditem displaying “System.Data.DataRowView” instead of actual value
  • Unit Testing MVC Web Application in Visual Studio and Problem with QTAgent
  • json Serialization in asp
  • Benchmarking RAM performance - UWP and C#
  • How can I remove ASP.NET Designer.cs files?
  • python draw pie shapes with colour filled
  • Are Kotlin's Float, Int etc optimised to built-in types in the JVM? [duplicate]
  • Is there any way to bind data to data.frame by some index?
  • costura.fody for a dll that references another dll
  • How can i traverse a binary tree from right to left in java?