我一直在尝试创建一个包含子域名的链接,看起来像 batman.website.com ,但它生成了 website.com/?subdomain=蝙蝠侠
我通过这种方法生成链接
@Html.RouteLink("Link", new { controller = "home", subdomain = activity.From.Username, id = activity.PostId, action = "post" })
我的路由routeconfig类看起来像这样
public static void RegisterRoutes(RouteCollection routes) {
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.Add(new SubdomainRoute());
}
}
子域路由很大程度上取决于此http://benjii.me/2015/02/subdomain-routing-in-asp-net-mvc/
有人能指出我正确的方向来正确格式化链接
答案 0 :(得分:0)
如果你使用MVC进行身份验证,你可以直接进入视图:
<a href="http://\\@HttpContext.Current.User.Identity.Name\\.website.com">Test Link</a>
另一种方法(如果您的身份验证不基于MVC)将在ViewBag上的View Controller中设置用户名,然后将其设置为在视图中显示:
控制器:
ViewBag.VarName = userName;
查看:
<a href="http://\\@ViewBag.VarName\\.website.com">Test Link</a>
另一个提供更多细节和示例的问题: How to get current user, and how to use User class in MVC5?
希望其中一些指向正确的方向!