Razor page not working with Rewrite

白昼怎懂夜的黑 提交于 2019-12-11 18:33:38

问题


I have a .cshtml page in a web forms app. When I go to the .cshtml url directly it displays the page just fine.

I also have a httpmodule that does url rewriting. When I rewrite a url to the .cshtml page I get an IIS error:

Server Error in '/' Application.

This type of page is not served.

Description: The type of page you have requested is not served because it has been explicitly forbidden. The extension '.cshtml' may be incorrect. Please review the URL below and make sure that it is spelled correctly.

Requested URL: /pages/1.cshtml

Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.1

Obviously this isn't right because I know the type of page can be served because it works when I go to the url directly.

My rewriter is doing this

HttpApplication.Context.RewritePath("~/pages/1.cshtml", true);

I am running this on IIS7.5 in Windows 7. Does anyone know why this error is coming up? Any suggestions on working around it?


回答1:


Found it here...

http://learn.iis.net/page.aspx/872/webmatrix-beta-release-readme/

You have to add this to your web.config

<system.webServer>
  <modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>


来源:https://stackoverflow.com/questions/5279774/razor-page-not-working-with-rewrite

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!