使用webforms进行路由和Ninject

时间:2011-11-02 16:55:44

标签: routing ninject

我正在尝试在我的网络应用程序中设置路由。

然而,在我的Global.asax中它似乎不适用于Ninject,但如果我在Global.asax中评论所有Ninject,那么这条路线就像一个魅力。

在文件中使用Ninject时,我在尝试打开路径页时只得到404“无法找到资源”。

以下是我的Global.asax代码中的内容:

<%@ Application Language="C#" Inherits="Ninject.Web.NinjectHttpApplication" %>
<%@ Import Namespace="Infrastructure.Storage" %>
<%@ Import Namespace="Ninject" %>
<%@ Import Namespace="Ninject.Modules" %>
<%@ Import Namespace="System.Web.Routing" %>

<script runat="server">

    void Application_Start(object sender, EventArgs e)
    {
        RegisterRoutes(RouteTable.Routes);
    }

    void Application_End(object sender, EventArgs e)
    {
        //  Code that runs on application shutdown

    }

    void Application_Error(object sender, EventArgs e)
    {
        // Code that runs when an unhandled error occurs

    }

    void Session_Start(object sender, EventArgs e)
    {
        // Code that runs when a new session is started

    }

    void Session_End(object sender, EventArgs e)
    {
        // Code that runs when a session ends. 
        // Note: The Session_End event is raised only when the sessionstate mode
        // is set to InProc in the Web.config file. If session mode is set to StateServer 
        // or SQLServer, the event is not raised.

    }

    protected override IKernel CreateKernel()
    {
        IKernel kernel = new StandardKernel(new SiteModule());
        return kernel;
    }

    public class SiteModule : NinjectModule
    {
        public override void Load()
        {
            //Bind<ILogger>().To<NLogger>().InSingletonScope();
            //Bind<IAuthentication>().To<Authentication>();
            Bind<ISession>().To<LinqToSqlSession>();
            Bind<IReadOnlySession>().To<LinqToSqlReadOnlySession>();
            //Bind<IReporting>().To<LinqToSqlReporting>();
        }
    }

    public static void RegisterRoutes(RouteCollection routes)
    {
        routes.MapPageRoute("City", "Cities/{id}", "~/test2.aspx");
    }

</script>

任何人都有可能出错的想法? 非常感谢。

此致 马丁

0 个答案:

没有答案