Question

i like to know what is the advantage of subdomain. suppose i have one domain like www.bba-reman.com and our web site has forum in the same project and people access forum pages of our web site typing url like www.bba-reman.com/forum/index.aspx but i often saw many site has subdomain for their forum section and people access their forum like

www.forum.bba-reman.com/index.aspx or forum.bba-reman.com/index.aspx

or www.forum.bba-reman.com

1) so i like to know what is the advantage of having subdomain ?

2) how to create sub domain for our forum page where we hosted our web site. briefly tell me what settings i need to do?

so how to write routing code which enable user to reach right page suppose when user type www.forum.bba-reman.com/index.aspx then request goes to forum controller action would be index etc

here i got a sample code which create a new route and adding it to the routes collection in RegisterRoutes in your global.asax but do not know does solve my purpose because i am new in MVC ?

public class ExampleRoute : RouteBase
{

    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 == "user1")
        {
            var routeData = new RouteData(this, new MvcRouteHandler());
            routeData.Values.Add("controller", "User1"); //Goes to the User1Controller class
            routeData.Values.Add("action", "Index"); //Goes to the Index action on the User1Controller

            return routeData;
        }

        if (subDomain == "user2")
        {
            var routeData = new RouteData(this, new MvcRouteHandler());
            routeData.Values.Add("controller", "User2"); //Goes to the User2Controller class
            routeData.Values.Add("action", "Index"); //Goes to the Index action on the User2Controller

            return routeData;
        }

        return null;
    }

    public override VirtualPathData GetVirtualPath(RequestContext requestContext, RouteValueDictionary values)
    {
        //Implement your formating Url formating here
        return null;
    }
}

http://blog.maartenballiauw.be/post/2009/05/20/ASPNET-MVC-Domain-Routing.aspx

Was it helpful?

Solution

Sub domains are websites that logically belong to your site.

according to my knowledge in a single domain you can create multiple domain.

If you want to speed up your website, you can make a browser open up more connections by using subdomains for things like images, javascript, css, etc.

For instance if you purchased example.com, you could use the following sub-domains which would all be housed under the "me" of example.com :

test1.example.com
test2.example.com
test.example.com
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top