在子域路由约束中,我想使用下面的代码将子域名传递给控制器。但是在控制器子域条目中缺少(仅存在操作和控制器条目)。这里有什么问题?或者我应该在控制器本身中嗅探子域(在 Request.Headers["HOST"] 的帮助下)?最佳做法是什么?
public class SubdomainRouting : IRouteConstraint
{
public bool Match(HttpContextBase httpContext, Route route, string parameterName, RouteValueDictionary values, RouteDirection routeDirection)
{
//
//get subdomain here
//
if (values.ContainsKey("subdomain") == false)
{
values.Add("subdomain", subdomain);
}
return true;
}
}