0
On Asp.Net MVC 3 URL의 하위 도메인 처리를 포함하도록 MvcRouteHandler 및 MvcHandler를 덮어 썼습니다.asp.net MvcHandler.ProcessRequest가 호출되지 않습니다.
그러나 MvcHandler의 ProcessRequest 메소드를 호출하지 않는 것 같습니다.
public class SubDomainMvcRouteHandler : MvcRouteHandler
{
protected override IHttpHandler GetHttpHandler(System.Web.Routing.RequestContext requestContext)
{
return new SubDomainMvcHandler(requestContext);
}
}
public class SubDomainMvcHandler : MvcHandler
{
public SubDomainMvcHandler(RequestContext context)
: base(context)
{
}
protected override void ProcessRequest(HttpContextBase httpContext)
{
string[] hostNameParts = httpContext.Request.Url.Host.Split('.');
int length = hostNameParts.Length - 3;
for (int i = length; i >= 0; i--)
{
if (hostNameParts[i] != "www")
RequestContext.RouteData.Values.Add("SubDomain" + (length - i + 1), hostNameParts[0]);
}
base.ProcessRequest(httpContext);
}
}
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
).RouteHandler = new SubDomainMvcRouteHandler();
}
모든 이유는 당신이 떨어져 알고 ? 내가 무슨 일이 일어나고 있는지 이해하고 싶습니다. –
'BeginProcessRequest'는 라우팅이 처리되고 완료되고 ControllerFactory가 인스턴스화되며 컨트롤러가 인스턴스화됩니다. 당신이 원하는 모든 것은 BeginProcessRequest가 완료 될 때까지 완료되었습니다. – counsellorben