剃刀页面不适用于重写 [英] Razor page not working with Rewrite

查看:120
本文介绍了剃刀页面不适用于重写的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在网络表单应用中有一个.cshtml页面.当我直接转到.cshtml网址时,它显示的页面就很好.

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

我也有一个执行网址重写的httpmodule.当我将网址重写为.cshtml页面时,出现IIS错误:

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.

不提供此类页面.

说明:您拥有的页面类型 所请求的不被送达,因为它已经 被明确禁止.这 扩展名".cshtml"可能不正确. 请查看下面的网址并进行 确保拼写正确.

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.

请求的URL:/pages/1.cshtml

Requested URL: /pages/1.cshtml

版本信息:Microsoft .NET 框架版本:4.0.30319; ASP.NET 版本:4.0.30319.1

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

显然这是不对的,因为我知道可以提供页面类型,因为当我直接进入url时它可以工作.

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.

我的重写者正在这样做

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

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

我正在Windows 7中的IIS7.5上运行此程序.有人知道为什么会出现此错误吗?有什么建议可以解决吗?

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?

推荐答案

在这里找到它...

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

您必须将此添加到您的web.config

You have to add this to your web.config

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

这篇关于剃刀页面不适用于重写的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆