How do I create SubDomains and redirect them to ASP.NET?

How do I create subdomains in ASP.NET? I have multiple links on my home page (Home.aspx) Example: Link1 and Link2

I need to create two child domains link1.example.com and link2.example.com and redirect them. I will be using Response.Redirect for navigation.

Questions: Do you need files in another directory or something? Can I test or simulate this example on localhost?

Any help for this newbie ASP.NET programmer would be appreciated.

+1


source to share


2 answers


Depending on what you are actually trying to accomplish with these redirects, it might be helpful. If you're just trying to use multiple subdomains from the same web application, you can fake this subdomain behavior outside of ASP.NET entirely by using an IIS based server hosting a single web application using an ISAPI rewrite tool like Ionics Isapi Rewrite Filter ( http://www.codeplex.com/IIRF ), assuming you have the option to add an ISAPI filter to your hosting environment.

Because the ISAPI filter is processed before ASP.NET knows about the request, you can host multiple subdomains (and full domains) from just one web application. Unfortunately, it is not possible to emulate this type of redirect on the ASP.NET Embedded Web Server (Cassini) because it does not use ISAPI. This method allows you to test the functionality of your final subdomains, but only at the final redirect location; you can't really check the original domain map in Cassini either since the windows hosts file doesn't allow port rules.

If you've set up one app to have pages handle the functionality of all your desired subdomains, you can simply redirect the request for the subdomain to your one app in the right place. It can be as simple as a folder of pages in one application that handles all the logic for your new subdomain. Here are some examples of Ionics rewrite rules that will send requests for different subdomains to the final location in your single web project:



RewriteCond %{HTTP_Host} ^(?~new-sub-domain.yourdomain.com).*$ [I]
RewriteRule ^(.*)$ http://www.yourdomain.com/new-sub-domain$1 [I,R=302]
RewriteCond %{HTTP_Host} ^(?~another-new-sub-domain.yourdomain.com).*$ [I]
RewriteRule ^(.*)$ http://www.yourdomain.com/another-new-sub-domain$1 [I,R=302]
# '#' is a comment marker in the rewrite files
# [I] at the end means case-insensitive
# [L] at the end  means last rule (sending the request on but hiding the forward from the end user)
# [R] at the end  means an official redirect and can be used instead of [L] (the end user will then see a new request, such as a 301 redirect using [R=301])

      

This will cause all requests to new subdomains to be sent to your existing project directory (/ new-sub-domain / and / another-new-sub-domain /, respectively); this can be changed to send them wherever you want within this project.

While this approach allows you to host multiple subdomains (and possibly multiple full domains) from a single application, the redirect / rewrite limitation on an ASP.NET web server (Cassini) will leave you limited to testing functionality from that end location (eg " / new-sub-domain / ").

+4


source


You need to set up domains and subdomains from the domain provider (where you bought the domain name from) and not from your ASP.NET website.



Locally, you cannot test this because you can only access http: // localhost as the dev webserver.

0


source







All Articles