asp.net mvc site with multiple subdomains in iis - asp.net-mvc

I want to do capture subdomain as a parameter and show the appropriate information based on subdomain.
for example user1.domain.com and user2.domai.com each one get appropriate info.
possible duplicate: Is it possible to make an ASP.NET MVC route based on a subdomain?
what i have done so far:
I have a dns server with following ip address: 192.168.1.11 and a web server which host bunch of websites with ip 192.168.1.12
The site the should capture the subdomain is named pakdomain.dev
I've tried two scenarios:
after defining pakdomain.dev zone on iis and creating and "A" record with www as host and ip 192.168.1.12 on dns server
fist i have created another "A" record with "*" as host and wildcarding it to ip webserver
second i have created another "CNAME" record with "*" as host and wildcarding it to www.pakdomain.dev
in iss i have a binding with www.pakdomain.dev and pakdomain.dev to a website.
none of the above scenarios have worked for me when i goto www.pakdomain.dev or pakdomain.dev everything is fine but when i try to go to address like user1.pakdomain.dev or user2.pakdomain.dev the it goes to default website on iis.
what should id ? and how should i capture subdomain on my app?

Try this
var domain = HttpContext.Current.Request.ServerVariables["HTTP_HOST"];
That should give you the host header information and then use the value to route to wherever it is you want to go.

Related

How to configure a reverse proxy for multiple IIS sites and a single IP?

I've inherited some internal sites from a previous employee and my constraints are the following, it is written in MVC and I need to change how it is hosted and no direct control over DNS. Security won't allow me to use subdomains within DNS so I'd like to use a subdomain within IIS or file path extension. manage.mgmt.domain.td or mgmt.domain.td/manage as an example.
How can I configure an IIS binding and an inbound proxy rule so that mgmt.domain.td directs to a general menu page, but manage1.mgmt.domain.td directs to a separate page and manage2.mgmt.domain.td to another page and have them fully functional. I've been able to configure the inbound reverse proxy rule to use an IP such as 10.0.0.1:801, however I cannot configure it to working using either friendly format listed above.
Can a vdir, appdir, work with an mvc project or is a reverse proxy better? It's iis10 .
https://computingforgeeks.com/configure-virtual-directory-on-windows-iis-server/
[Edit adding IIS binding and reverse proxy rule image]
Current
ASP.NET applications run in application pool. When you add vdir, you cannot choose application pool. So add application is more suitable than vdir.
I can type in the ip 10.0.0.1/manage and it points to my site, I can also type 10.0.0.1 and it will load the same content (which I dont' want)
10.0.0.1/manage is the correct url to access MVC application. If 10.0.0.1 also show same content, consider that client cache or url redirect. The correct content it shows should be index page of the main site.
however it is not loading content when I use the dns friendly name?
I cannot understand what the dns friendly name you mean. If you have a public domain name, just bind the domain to the server in server provider. and when you add site, set the host name to it.
An easier way to do this is to add a route to your application, for example on global.asax, to get the incoming server address from there and direct it to the correct destination. For Application_Begin_Request in Mvc, you can refer to this article here.

Host Sub Application to main application with out change the URL

I have one doubts, Please clarify this
We have currently host the one sub application to under main application. like below
URL like
www.Examples.com/internal
internal is a sub application hosted under Examples main application.
But, i want to host the sub application as main application like below
But, the URL should be same like
www.Examples.com/internal
Note: Internal application maintain in single server or different server but, the URL should be same.
Is there any posibilities to maintain website like this?
Thanks,
Mathan Kumar H J
A more common way is having your root zone, example.com, and making other projects DNS records on that zone, for example, if you host the internal app at Ipv4 1.2.3.4 then you would make the DNS record internal IN A 1.2.3.4 in your zone and then internal.example.com will resolve to your app
Edit: noticed you do not want to change the url - if the other site is running on its own server, then you would have to get the user to that server eventually, so if you did it the example.com/internal way you would have to 301 redirect to that ip which would end up changing the url anyway

How do I change the url of my IIS hosted site?

Currently, my .NET MVC application hosted on IIS 7 can be accessed remotely with the following url:
http://172.21.1.83:8080/Mysite/Index
I want to be able to use the url
http://example.com/Mysite/Index instead.
How do I achieve this? Basically I just want to get rid of the ip address and port number in the url, and replace it with a custom domain name (like example.com).
Sounds like you need a reverse proxy. That way the user doesn't have to see or use the port. Check out this article.
http://www.myconnectionserver.com/support/tutorials/v90/iisProxy/index.html
In your IIS web application click on Bidings from the right side menu bar, and add a new biding by entering your IP address and Port number, and your Host Name as the domain name which in your example is http://example.com/Mysite/Index.

IIS URL Rewrite domain to one of several VMs

I have a server running several Virtual Machines. Each VM runs IIS 8.0 and hosts a variety of different sites. The base server is also running IIS 8.0 and I'm intending that it directs requests to one of of the VMs depending on the HTTP_HOST.
I'm trying to define the inbound and outbound rules to achieve the following:
www.mydomain1.com requests are directed to VM 192.168.1.10/mydomain1
www.mydomain2.com requests are directed to VM 192.168.1.10/mydomain2
www.mydomain3.com requests are directed to VM 192.168.1.11/mydomain3
www.mydomain4.com requests are directed to VM 192.168.1.11/mydomain4
What I want is for the user to see www.mydomainx.com all the time while the internal VM serves up the pages seamlessly without changing the URL. I've spent hours trying every combination I can think of and read dozens of posts but none seem to cover this particular scenario.
I've got subdomain to folder working (mysub.mydomain.com -> 192.168.1.10/mysub but not full domain name.
Any suggestions gratefully received.
After a lot of searching and testing I've finally found the solution. Instructions below relate to IIS 8.5.
Install Application Request Routing Extension for IIS
Install URL Rewrite 2.0 for IIS
Restart IIS Manager and you should see a new node called Server Farms
For every Virtual Machine that hosts websites, create a Server Farm, then add the IP address of the VM as a server in that farm. In my set up I have one VM per Server Farm.
Once you have all your VM's set up in their own Server Farm, select the root server node in IIS and double-click URL Rewrite
For each VM create rules for all the domains being handled.
Add a new blank rule
Add an appropriate name and set the Pattern to .* - regex for all matches
In the Conditions section, click Add
Set Condition input to {SERVER_NAME}
Make sure input string dropdown is set to Matches the Pattern
Set the pattern to ^(www.)?yourdomain.com$ - set the domain name appropriately and click ok
Add conditions for every domain name that will be handled by the VM
In the Action section, set Action Type to Route to Server Farm
In the Action properties, select the server farm that will handle these domains
Click Apply
Now all you need to do is set up your router to port forward requests on port 80 to your base IIS server and it will then route traffic based on the domain names to the appropriate Virtual Machine.
I have four Virtual Machines set up this way the routing is seamless and works really well.

URL redirect to port

I have set up SAB, Sickbeard, CouchPotato & Plex on my home media server. All mapped to respective ports.
The ports have been forwarded correctly and I have DDNS enabled, if I browse to my DDNS address proceeded by the port number - I can access my services absolutely fine.
What I am wanting to do is use sub-domains on a domain that I already own to make the URLs a bit more friendly. However I have tried setting up simple web redirects & these don't work for some reason.
For example;
sab.domain.com = DDNS_address:9090
plex.domain.com = DDNS_address:32400/web/index.html
When trying to access I get 404 Not Found errors.
I don't host my own IIS or Apache server, the domain is hosted by an online provider.
Is this possible or worth too much hassle?
Thanks.

Resources