Dynamic (database) IP Blocking with SQL on IIS 7.5 - asp.net

I am using IIS7.5 URL rewrite module to look up redirect and rewrites in the SQL database attached to my website - and am now trying to use the same system to look up a list of IP address I wish to block (return 403).
I have a table of IPs (in SQL server) which is continually updated (outside of the remit of this question) and I want IIS to pass the IP address of the current request to a stored procedure which will then return a Pass/Fail on whether to allow the request to continue or return a HTTP 403.
I don't seem to be able to work out how to configure this in IIS.
Many thanks

Related

IIS to handle api and website on same port

I have an API built with asp.net and its hosted using OWIN.hosting.WebApp as a Windows Service at https://example.com/api/v1/myEndpoint. Its bound to port 443 through netsh. When i start the OWIN application, its done like:
Dim Address As String = "https://*:443/
WebApp.Start(Of Application)(Address)
I also have my website hosted in IIS using SSL and bound to port 443 - https://example.com/web
They both start up and run without error. But it seems like IIS is blocking requests to the https://example.com/api/v1/myEndpoint. Postman cannot reach the API while IIS is running. If i stop IIS and try the exact same postman request the API returns back data like it should. As soon as i start IIS back up, the API will no longer respond.
Is there a rewrite rule i can add to forward the API requests the API service?
In my opinion, you could not host the asp.net web API windows service in iis.
a single IIS server can host multiple websites, but in order IIS to distribute HTTP requests correctly, each website has to be identified with some unique value. In case of an IIS website, it consists of three attributes that make up a unique combination for each website. These are:
a TCP port number
an IP address
a host header
The information about the hosted websites is stored in the ServerBindings attribute of the IIS Metabase in the following format: IP:Port:Hostname. Thus, if you want to host multiple websites on the same port, you will have to use a unique Host header or Ip address.
You could refer below link for more detail:
http://woshub.com/run-multiple-websites-on-the-same-port-and-ip-address-on-iis/

IIS redirect users to another server

I have two IIS instances running on different servers with identical code base. The application that runs on these servers reads from a same SQL database. I was wondering if sending users from one server to another possible?
create iis rewrite rule to then rewrite to specific server within a server farm
for your instance you will use "rewrite" instead of "rewrite to server farm"
check this link to see how to setup rewrite action (ARR as a Forward Proxy)
http://www.iis.net/learn/extensions/configuring-application-request-routing-(arr)/creating-a-forward-proxy-using-application-request-routing

IIS website inaccessible from server (but ok from outside)

On a server where an IIS website is hosted, if I open IE or Firefox and type the IIS website url, i got an error after a few seconds ("Cannot display the webpage", just like website would be offline). If I do the same from the exterior (as normal user do) everything works.
I have tried to give the IP address directly (thus skipping DNS), problem is the same. It only works if I type the internal ip address of the IIS website (eg : 10.0.0.x).
The reason I want to do that is that I need to access a specific page of the website in order to execute a scheduled task. I cannot use internal ip address to do that, because host name (HttpContext.Current.Request.Url.Host) is used inside ASP.NET code to switch between different configuration.
Here is my question : is it possible to access a specific page on a IIS website from server where website is hosted ? (using complete url, not internal ip address ?)
Yes - If I understand your question correctly you should be able to add a mapping in your local hosts file to point that domain at your IIS webserver.
e.g.
10.0.0.x my.example.hostname
(where x is obviously a number)
We use this configuation internally when developing multiple sites on our local machines - each site is bound to a specific hostname and all these hostnames have mappings in the 'hosts' file to 127.0.0.1
The same principal applies here, if I've understood the question correctly :)

Why is my fully qualified domain name request url getting converted to an ip address request url by the Cassini web server?

I have a web application which depends on the browser client retaining the FQDN in order for it to work, but what is happening is that in multiple browsers I am seeing the url get converted into an ip address url (containing the correct IP address) which is getting changed by a redirect from the web server.
The web server hosting the resource is Cassini, and the HttpRequest class Url property is returning the IP address in the URL instead of the FQDN.
Any suggestions on how to change this behavior?
This is probably a misconfiguration in your web server. In apache (for example), one can set the canonical host name to be used when doing certain rewrite procedures using the ServerName directive. One common one is when the web server adds slash to the end of your URL ("http://example.com/path" → "http://192.168.1.1/path/").
I recommend taking a peek at what's going on with curl.
This is not a DNS issue, it's a web server configuration issue.
Yes, the DNS is used to convert the hostname part of the URL into an IP address.
However that IP address will never appear in the browser bar unless the web server tells it to by sending a redirect.
Thanks to the helpful information provided, I was able to track down this issue to an incomplete implementation of the HttpWorkerRequest abstract class of the .NET Framework as part of the Cassini implementation. The Cassini implementation failed to override the GetServerName and the base implementation was returning the IP address instead of the domain name.

How can I get the Url of the web site which is using my web service?

I have developed a web service and host it on my server and I would like to know who is using this web service (site Url). I tryed to use "Request.UrlReferrer" but it is not returning any thing! any suggestions/Advices?
You can't get the URL of the caller of a web service as not all callers have canonical URL's. You can however get the IP Addresses assuming that they are not behind a proxy / nat. In which case you'd get the IP of the nat / proxy.
Assuming your using an ASMX web service you can this from:
HttpContext.Current.Request.UserHostAddress
Once you have the IP Address you can try and do a reverse lookup to get the host name. I would recommend storing the IP address then writting an offline process which goes and tries to determine who owns the IP. I'm sure there are some webservices out there to help with this.
You can use Request.Url property to get all the information about the requests to your web service.
The referrer is set by the client, and the client can not set it. That is why you see nothing. If the client's are servers, then the best you can do is to get the IP of the client connection and go to that IP. If a simple setup, with no virtual hosts, then that is the "web site" that is hitting your web service.
As Josh states, the HttpRequest object is the way to go, there are a few properties on there that might help:
UserHostName - Gets the DNS name of the remote client.
UserAgent - Gets the raw user agent string of the client browser.
UserHostAddress - Gets the IP host address of the remote client.
Which might give you a bit more information to play with.

Resources