精简路由上下文信息格式,显示更多重要的信息,避免显示重复的信息 隔离静态路由到模块和运行时路由的模块的模块对象实例缓存 调整运行时路由到模块的API,使可以按需要调整路由片段信息,以显示更多信息 修正重定向路由不能重定向到网站根路径的问题 修改Mvc测试网站相关测试代码和说明
netwjx authored at 2012-02-17 16:23:46
1.03 KiB
X
using System;
using System.Collections.Generic;
using System.Text;
using NewLife.Mvc;
using System.Web;

class RouteFactory : IControllerFactory
{
    public IController GetController(IRouteContext context)
    {
        HttpRequest r = HttpContext.Current.Request;
        string host = r.Headers["Host"];
        string[] hostport = host.Split(':');
        int port = 80;
        if (hostport.Length > 1)
        {
            Int32.TryParse(hostport[1], out port);
        }
        host = hostport[0];
        if (host.EndsWith("test.localhost"))
        {
            try
            {
                return context.RouteTo<TestModuleRoute>();
            }
            catch
            {
                ModuleRule m = new ModuleRule();
                m.Module = new TestModuleRoute();
                context.RouteTo("", m); // 自行控制模块和模块路由配置实例初始化
            }
        }
        return null;
    }

    public void ReleaseController(IController handler)
    {
    }
}