Routing 使用webforms路由和Ninject
我正在尝试在我的web应用程序中设置路由 但是,在我的Global.asax中,它似乎不适用于Ninject,但是如果我在我的Global.asax中对所有的Ninject进行注释,那么这个路线就像一个符咒 由于文件中有Ninject,在尝试打开路由页面时,我只得到404“资源找不到” 以下是我的Global.asax代码:Routing 使用webforms路由和Ninject,routing,ninject,Routing,Ninject,我正在尝试在我的web应用程序中设置路由 但是,在我的Global.asax中,它似乎不适用于Ninject,但是如果我在我的Global.asax中对所有的Ninject进行注释,那么这个路线就像一个符咒 由于文件中有Ninject,在尝试打开路由页面时,我只得到404“资源找不到” 以下是我的Global.asax代码: <%@ Application Language="C#" Inherits="Ninject.Web.NinjectHttpApplication" %> &
<%@ 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>
无效应用程序\u启动(对象发送方,事件参数e)
{
注册地址(RouteTable.Routes);
}
无效应用程序\u结束(对象发送方,事件参数e)
{
//应用程序关闭时运行的代码
}
无效应用程序错误(对象发送方,事件参数e)
{
//发生未处理错误时运行的代码
}
无效会话\u启动(对象发送方,事件参数e)
{
//启动新会话时运行的代码
}
无效会话\u结束(对象发送方,事件参数e)
{
//会话结束时运行的代码。
//注意:只有在sessionstate模式下才会引发Session_End事件
//在Web.config文件中设置为InProc。如果会话模式设置为StateServer
//或SQLServer,则不会引发该事件。
}
受保护的覆盖IKernel CreateKernel()
{
IKernel kernel=新的标准内核(新的SiteModule());
返回内核;
}
公共类SiteModule:NinjectModule
{
公共覆盖无效负载()
{
//绑定().To().InSingletonScope();
//绑定()到();
绑定()到();
绑定()到();
//绑定()到();
}
}
公共静态无效注册表项(路由收集路由)
{
MapPageRoute(“City”、“Cities/{id}”和“~/test2.aspx”);
}
有人知道什么地方出了问题吗?
非常感谢
问候
Martin可能重复的问题请不要发布重复的问题,而是编辑您的原始帖子。