0

I've been trying to create a link that includes the subdomain to look like this batman.website.com, but instead it generates this website.com/?subdomain=batman

I'm generating the link through this method

@Html.RouteLink("Link", new { controller = "home", subdomain = activity.From.Username, id = activity.PostId, action = "post" })

and my routing routeconfig class looks like this

public static void RegisterRoutes(RouteCollection routes) {
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
            routes.Add(new SubdomainRoute());
        }
}

the subdomain route is heavily based off of this http://benjii.me/2015/02/subdomain-routing-in-asp-net-mvc/

Could someone point me in the right direction to format the link correctly

Manfred Radlwimmer
  • 13,257
  • 13
  • 53
  • 62
dbomb101
  • 413
  • 1
  • 8
  • 21
  • 1
    So you're just trying to generate the dynamic link to a subdomain, and not trying to setup your MVC app to accept incoming connections based on that subdomain? – Jordan Nov 16 '16 at 14:50
  • I feel like this might be helpful: [ASP.NET Subdomain Routing](http://stackoverflow.com/questions/278668/is-it-possible-to-make-an-asp-net-mvc-route-based-on-a-subdomain) – Kuba Nov 16 '16 at 14:51
  • @Jordan Yeah I'm just trying to generate the links at this point, I've already got it setup so that if you typed that in it would go to the right page – dbomb101 Nov 16 '16 at 14:52
  • @Kuba I've already set up the page to accept those kind of links, at this point I'm just trying to generate the links look correct – dbomb101 Nov 16 '16 at 14:56
  • Okay, so you're just trying to setup a link using the user's Username as in: username.website.com? If so, just use a static href and and "@" statements in your view. I can submit an example if that is correct. – Jordan Nov 16 '16 at 15:10
  • @Jordan Yeah that's pretty much what I'm trying to do and an example would be great ! – dbomb101 Nov 16 '16 at 15:18

1 Answers1

0

If you're using MVC for authentication, you could do something like this, straight into the view:

<a href="http://\\@HttpContext.Current.User.Identity.Name\\.website.com">Test Link</a>

Another way (if your authentication isn't based on MVC) would be to set the username at the View Controller on the ViewBag and then set it to display in the view:

Controller:

ViewBag.VarName = userName;

View:

<a href="http://\\@ViewBag.VarName\\.website.com">Test Link</a>

Another question that gives more detail and examples: How to get current user, and how to use User class in MVC5?

Hopefully some of this points you in the right direction!

Community
  • 1
  • 1
Jordan
  • 2,992
  • 2
  • 20
  • 29