我有一个常规的webforms项目(非MVC),我成功实现了MapPageRoute和RedirectToRoute场景。页面路由由数据库查找完成,因为我正在翻译查询字符串(例如?filter = 112到/ my-friendly-url)。它在我运行VWD 2010 Express的开发机器和附带的ASP.NET开发服务器上运行良好。 ASP.NET版本是4.0.30319.272。但是,当我在生产(iis7)框上运行项目时,我在映射页面上找到页面未找到错误。其余的网站/页面运行正常。我的直觉是页面处理是问题的根源,但我无法弄清楚它是什么或为什么。它可能与iis7如何处理目录与文件名以及我的程序将物理.aspx路由到目录样式名称可能产生的干扰有关。我的iis7& web.config知识在这方面有点弱。
这是我的global.asax的摘录:
void Application_Start(object sender, EventArgs e)
{
// Code that runs on application startup
RegisterRoutes(RouteTable.Routes);
}
public static void RegisterRoutes(RouteCollection routes)
{
routes.Clear();
routes.RouteExistingFiles = false;
routes.Ignore("{resource}.axd/{*pathInfo}"); //ignore axd files, prevents javascript/routing collisions
routes.MapPageRoute("Education", "{category}/{section}", "~/product/education/default.aspx");
routes.MapPageRoute("EducationLanding", "{category}", "~/product/education/default.aspx");
}
Web.config:
的处理程序部分 <handlers>
<remove name="StaticFile" />
<remove name="PageHandlerFactory-Integrated-4.0" />
<add verb="*" path="ajax/*.ashx" name="Ajax" type="Ajax.PageHandlerFactory, Ajax" />
<add name="ScriptResource" preCondition="integratedMode" verb="GET,HEAD" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
<add name="PageHandlerFactory-Integrated-4.0" path="*.aspx" verb="GET,HEAD,POST,DEBUG" type="System.Web.UI.PageHandlerFactory" resourceType="Unspecified" requireAccess="Script" preCondition="integratedMode,runtimeVersionv4.0" />
<add name="StaticFile" path="*" verb="*" modules="StaticFileModule,DefaultDocumentModule,DirectoryListingModule" resourceType="Either" requireAccess="Read" />
</handlers>
提前致谢, 约翰
答案 0 :(得分:3)
查看页面处理使我进入了web.config的模块部分,我在SO(IIS 7 ignores MapPageRoute without file extentions)上找到了我的答案。为什么我在之前的所有搜索中都没有找到这个,我不知道。看哪:
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>
谢谢@Christoph
答案 1 :(得分:0)
这一切都很好,但是请不要忘记需要重新启动服务器才能触发global.asax的Application_Start。