How do I route incoming requests to specific apps based on IP? - c#

How would I route requests to different IIS apps based on the user's IP address?
I'm looking to pilot a test version of a production site to a specific IP address. I would rather not have to force these users to access a separate URL. So, I'm asking if there is a way within IIS to force the server to process the request via a secondary app based on the requesting user's IP address?

This is possible on IIS 7+ using application request routing:
http://www.iis.net/downloads/microsoft/application-request-routing

Related

Get FQDN (fully qualified domain name) from client machine

I'm working on a project that will include Windows tablets as a Terminals and they will be under VPN. Setting up the tablets will not be our job, we only need to provide some endpoints for them and we'll need to authenticate the API calls from them with their FQDN. The project is .net5 Web API.
Previously the requirement was that we will use the IP address of the terminals for authenticating them and I can easily use this code for getting that:
var remoteIpAddress = HttpContext.Connection.RemoteIpAddress?.ToString();
However the request was changed and we will need to use FQDN for authentication.
The problem is that I can not get FQDN from HTTP Context as I can take the IP address.
Is there any way to get this parameter from the device?

How to tracing client IP from the original request in C# MVC 4?

I created 3 projects WebSite, WebApi and CoreAuthWebApi. They all interact with each other.
Here is the request flow:
WebSite --> WebApi --> CoreAuthWebApi
CoreAuthWebApi --> WebApi --> WebSite
What is the best way for CoreAuthWebApi to get the WebSite Client IP without IP spoofing?
What is the best way for CoreAuthWebApi to get the WebSite Client IP without IP spoofing?
If the call is made on behalf of the web site, the API has no way of knowing the IP of the user agent unless you pass it as parameter. Remember the client of the API in this case is the IP of the server where the website is hosted.
Since the website knows the IP of the user agent it can pass it to the API as parameter.

How to create subdomains for IIS7 programmatically?

I'm writing a SaaS app in C#/ASP.NET, hosted with IIS7. I want to create a personalized subdomain for every customer that signs up, i.e. fred.mydomain.com, bob.mydomain.com, each of which will point to the same app, just with a different skin per customer.
How do I create these subdomains programmatically?
Use URL Rewrite for IIS7 to map all requests like user.mydomain.com (where user is not www, mail or other existing real subdomains) to mydomain.com/myapp?id=user Then in the script handle whatever theming you need.
You do not need to add rule for every user created. Just create one general rule to do so.
And, also, in your server DNS, you need to forward *.mydomain.com (where * is not www, mail or other existing real subdomains) to mydomain.com IP. This is pretty straight forward. You already have DNS records for existing subdomains. Just add *.mydomain.com and point to mydomain.com. This will do the DNS part of the trick. Other part is in the URL Rewrite
Realizing of course that someone already answered your question by telling you to do redirects, it seems the easier way might be to just grab the host server variable.
Setup IIS so that all incoming requests (regardless of the host
header) point to this one application. All sites have to either have a unique hostname or unique port in IIS, so you would set this up by:
Binding the site to the default port of 80.
Not providing anything in the Host Name field. This is also how the Default Website is setup by default when you first install IIS.
Figure out the static IP address of your server, and tell each new client that signs up to point the DNS for their domain to that IP. Or, if you will own the domain name, setup a catchall DNS entry: *.mydomain.com - points to the IP address of your server.
Within your application, check for the current
host header in order to provide a
different skin or master page.
This should grab the host header from within the code:
Request.ServerVariables["HTTP_HOST"]
From there you could test its value against a set of database values you have to determine which MasterPage/css stylesheet/etc you need to load based on that URL. Keep in mind if you do a catchall like this that you'll need to account for a URL mistyped that you therefore wouldn't have a skin to match to it.

.NET Web Service Security

I have a C# web service on our website and I only want to be able to call it locally where its hosted - restricting access from the outside world. Whats the easiest way to do this without a login form? We cannot restrict the web service directory per ip (because I don't believe its static)
Alternatively, you could also host them on a separate website, which you only bind to localhost (127.0.0.1)
PS: You should really get a static IP for your webserver. Or at least reserve an IP address for the server's mac address in your DHCP server configuration.
You can setup windows authentication on the web services and require the authentication be a local account to that machine. You'll have to modify your code calling it by providing network credentials, but that will prevent people from the outside calling it.
This article should explain how to do it.

How can I create a subdomain in asp.net?

How can I create a subdomain in an asp.net C# application? I am working with an asp.net portal. In that portal I need to be able to create the subdomain at runtime. The ftp for that subdomain also needs to be the same as the main domain ftp.
There are a handful of working parts here. It sounds like the requirement is that this all happen at runtime. I am sure a lot of web hosting providers are deep into these sets of problems and likely have custom solutions.
DNS: you'll need to have an API open at the DNS host. If it's a LAN environment, you'll have to check your DNS provider on whether they have APIs exposed. (i.e. Windows Server or whatever your network operating system is). If this is a public facing site that needs to be accessed via the internet, you'll have to get those APIs from the DNS registrar. Are the subdomains to be permanent?
IIS: You'll have to setup wildcard mapping, (i.e. *.mydomain.net). When an HTTP request comes in, logic within the ASP.NET page can determine the subdomain that you're working with. You could extract the subdomain, perform a lookup on that subdomain to get more information (CustomerID, names, valid visitor IP address ranges, whathaveyou).
FTP: if you require secure logins for that subdomain, you'd have to have created AD or local machine accounts for those users. If you want anonymous access, that's OK too. There are some scripting options that you'll have to look at to have that FTP folder setup as well. That is assuming you're using IIS's FTP module. If you are using a 3rd party FTP application, that complicates the scenario even further. Their APIs would have to be investigated.
Active Directory: If you are requiring secure access for each subdomain, you'll have to create AD users and/or groups. You can certainly script the creation of users into groups. Perhaps the users will be local to your web server. That doesn't scale well if you want to add another web server, but it's certainly do-able.
subdomain's are controlled by your dns settings. Beyond that I can't understand your question.
I think the best way is to have a wildcard DNS entry - i.e. *.domain.com that points to the domain. And then use a rewriting tool, like helicontech.com, to rewrite the 1st part of the subdomain to tell your app what you're looking at.
This would use regular expressions to pass the subdomain to your app:
RewriteCond Host: (mysub).domain.com
RewriteRule (.*) /$2?subdomain=$1 [I,L,U]
There are two halves to this:
A) Changing your DNS Settings:
This varies based on your host and whatnot. Contact them and ask if you can't figure it out.
B) Changing your host settings:
This varies based on your server. I assume you're using some version of IIS.
In IIS6, you can right click a web site, select the properties page, go to the web site tab, select advanced in web site identification, and start adding bindings (Generally you'll use default or the ip address for IP Address, 80 for TCP Port (unless SSL), and the site for the host header file (e.g. www.example.com or subdomain.example.com).
In IIS7, you right click on a website and select edit bindings, then click "Add". IIS7's add screen is pretty self explanatory.
I think he wants to created a subdomain from code, using an API probably that needs to be provided by his webhost folks. Like his own DNS manager app. If I interpreted your question wrong, then I guess you probably oughta reiterate a bit more.

Categories

Resources