none
MVC subdomain RRS feed

  • Question

  • Hello,

    Please help with setting subdomain routing in MVC5 app! 

    Things I've done!

    -I have set up a dns with wildcard (*.mydomain.com)

    -I have a field in the database table that stores subdomain names, basically, I am user's lastname and appending it to the  domain.

    For example, user John Smith  creates account on my site. On successful login, I want the url to look like this:

    https://smith.mydomain.com.

    To achieve this, I have followed tutorial on this link: https://benjii.me/2015/02/subdomain-routing-in-asp-net-mvc/

    but no success at all.

    -I have tried to persist the url on successful login  by merely  doing this:

    return Redirect(new UrlHelper(this.Request.RequestContext).Action("MyActionMethod", "MyController", null, this.Request.Url != null ? this.Request.Url.Scheme : "http", "smith.mydomain.com"));

    But when I redirect, All the login Sessions is reset to null thus making a user as not logged in. Please Help

    • Moved by CoolDadTx Friday, February 9, 2018 10:39 PM ASP.NET related
    Friday, February 9, 2018 6:26 PM

All replies

  • This is an odd thing to want to do.  The DNS system is simply supposed to find a server, not provide user validation.  What are you going to when Steve Smith enrolls, when John Smith is already there?

    If I were you, I would consider appending the name to the URL path, not to the domain.  For example, http://mydomain.com/smith.  That way, any cookies that you had sent at the top level will keep being sent, which will maintain your session data.


    Tim Roberts, Driver MVP Providenza & Boekelheide, Inc.

    Friday, February 9, 2018 10:32 PM
  • Please post questions related to MVC in the ASP.NET forums.

    Michael Taylor http://www.michaeltaylorp3.net

    Friday, February 9, 2018 10:39 PM
  • Tim,

    Thanks for the reply! I provided John Smith as example. Each user in the system has a  distinct subdomain. I am only having hard time how to keep session data.

    Friday, February 9, 2018 10:46 PM