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 7984495
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T11:17:16+00:00 2026-06-04T11:17:16+00:00

Possible Duplicate: How to get RouteData by URL? public override RouteData GetRouteData(HttpContextBase httpContext) {

  • 0

Possible Duplicate:
How to get RouteData by URL?

public override RouteData GetRouteData(HttpContextBase httpContext)
        {
            var url = httpContext.Request.Headers["HOST"];
            var index = url.IndexOf(".");

            if (index < 0)
                return null;

            var subDomain = url.Substring(0, index);

            if (subDomain != "www" && subDomain != "m")
            {
                var routeData = new RouteData(this, new MvcRouteHandler());
                    routeData.Values.Add("controller", "Business"); 
                    routeData.Values.Add("action", "Display"); 
                    routeData.Values.Add("id", subDomain);
                return routeData;
            }

            if (subDomain == "m")
            {
                var routeData = new RouteData(this, new MvcRouteHandler());
                routeData.Values.Add("controller", "Mobile"); 
                routeData.Values.Add("action", "Index"); 

                return routeData;
            }

            return null;
        }

My problem is that when I access xyz.mydomain.com it is always rerouted to xyz.mydomain.com/Business/Display/xyz. This is preventing me from going to xyz.mydomain.com/Overview as it’s picking up the subdomain and redirecting.

I have tried using if statements to determine if a controller is specified, but nothing seems to work. Any suggestions?

  • 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-06-04T11:17:18+00:00Added an answer on June 4, 2026 at 11:17 am

    Just in case anyone else needs an answer this was my solution…
    The substrings.Length >= 3 is for a controller then an action so change to 2 if you only need a controller :

    public override RouteData GetRouteData(HttpContextBase httpContext)
                {
                    var host = httpContext.Request.Headers["HOST"];
                    var url = httpContext.Request.RawUrl;
                    Regex regex = new Regex("/");
                    string[] substrings = regex.Split(url);
                    if (substrings.Length >= 3)
                    {
                        return null;
                    }
                    var index = host.IndexOf(".");
                    if (index < 0)
                    {
                        return null;
                    }
    
                    var subDomain = host.Substring(0, index);
    
                    if (subDomain != "www" && subDomain != "m")
                    {
                        var routeData = new RouteData(this, new MvcRouteHandler());
                            routeData.Values.Add("controller", "Business"); //Goes to the User1Controller class
                            routeData.Values.Add("action", "Display"); //Goes to the Index action on the User1Controller
                            routeData.Values.Add("id", subDomain);
                        return routeData;
                    }
    
                    if (subDomain == "m")
                    {
                        var routeData = new RouteData(this, new MvcRouteHandler());
                        routeData.Values.Add("controller", "Mobile"); //Goes to the User2Controller class
                        routeData.Values.Add("action", "Index"); //Goes to the Index action on the User2Controller
    
                        return routeData;
                    }
                    return null;
                }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Get URL of ASP.Net Page in code-behind I'm trying to hold current
Possible Duplicate: PHP REGEX: Get domain from URL I am working on a project
Possible Duplicate: How to get Url Hash (#) from server side c# get complete
Possible Duplicate: Get column index from label in a data frame I need to
Possible Duplicate: Get Variable from httpcontext coming from NSUrlRequest This question will be a
Possible Duplicate: Get query string values in JavaScript Say if,i've a URL like this
Possible Duplicate: Get current URL with JavaScript? How do you get the address of
Possible Duplicate: Get entire URL, including query string and anchor I have my url
Possible Duplicate: (C#) Get index of current foreach iteration Good morning, Is there any
Possible Duplicate: get the value of an url response with curl I have an

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.