Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 329827
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T09:37:28+00:00 2026-05-12T09:37:28+00:00

I am trying to develop an asp.net site with multiple subdomains. I am new

  • 0

I am trying to develop an asp.net site with multiple subdomains. I am new to web sites in general, and asp.net in particular. However, it seems that wildcard subdomains are properly setup with a combination of dns entries and web server configuration – which isn’t going to happen on my development machine. Therefore I’m manually inserting entries in my windows hosts file:

127.0.0.1  localhost
127.0.0.1  abc.localhost
127.0.0.1  xyz.localhost

However, when I try to interrogate the Request.Url property there is no subdomain to be seen. For example, if I hit http://abc.localhost:1660/ in the browser I get http://localhost:1660/ from Request.Uri.ToString(); the abc is just gone?!

I don’t know why the hosts file works like this, but is there any other method I can use to get subdomains into my local web application? Thank you all.

Note that I’m only using the built-in asp.net development server rather than a full iis server. (I can’t get access to a full IIS this weekend, but I would still like to know if that would help.)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T09:37:28+00:00Added an answer on May 12, 2026 at 9:37 am

    You can get the requested domain with Subdomain intact by using “Request.Headers[“HOST”]“. Here’s a simple method that returns the Subdomain of the current request. This method also assumes that you have a “.COM”, “.NET”, etc. after the domain just like the real web. So you’ll want to change your HOSTS file to include “localhost.com”, “abc.localhost.com”, etc.

    public string subdomain()
    {
        string host = Request.Headers["HOST"];
        if (!string.IsNullOrEmpty(host))
        {
            var parts = host.Split('.');
            if (parts.Length > 2)
            {
                return parts[0];
            }
        }
        return string.Empty;
    }
    

    I was searching on this very thing and here’s an article that is what actually helped me figure this out:
    https://web.archive.org/web/20090813174916/http://blogs.securancy.com/post/ASPNET-MVC-Subdomain-Routing.aspx

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to develop my first site in ASP.Net using Web Forms. I have
Im trying to develop my first ASP.NET MVC web app and have run into
I am trying to develop the single page in asp.net web mobile application as
I'm trying to develop some web page in Asp.Net and C# which almost look
I'm new to asp.net, mvc3 and entity framework. I'm trying to develop a mvc3
I'm totally rewriting the question.. I'm new to ASP.Net, and trying to develop a
I'm trying to develop a custom control for asp.net that will have the following
I am a New ASP.NET Developer and I am trying to develop a simple
I am trying to develop a .NET Web Project using NHibernate and Spring.NET, but
I am trying to develop a web application that will do the following: Collect

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.