在 ASP.NET Web 应用程序中禁用 Razors 默认 .cshtml 处理程序

发布于 2024-11-17 07:30:05 字数 1524 浏览 2 评论 0原文

有谁知道如何从 ASP.NET Web 应用程序中完全禁用 .cshtml 扩展名?

本质上,我想劫持 .cshtml 扩展名并基于 RazorEngine 主机提供我自己的实现,尽管当我尝试直接访问 page.cshtml 它似乎正在我试图禁用的现有 WebPages razor 主机下运行。

注意:看起来正在执行 .cshtml 页面下 System.Web.WebPages.Razor 上下文 作为 Microsoft.Data 数据库已初始化。我什至不 有任何 Mvc 或 WebPages dll 引用的,只是 System.Web.dll 和 System.Web.Razor 的本地副本 RazorEngine.dll

我创建了一个新的 ASP.NET Web .NET 4.0 应用程序,并尝试清除所有 buildProviders 和处理程序,如下所示:

<system.web>
    <httpModules>
        <clear/>
    </httpModules>
    <compilation debug="true" targetFramework="4.0">
        <buildProviders>
            <clear/>
        </buildProviders>
    </compilation>

    <httpHandlers>
        <clear/>
        <add path="*" type="MyHandler" verb="*"/>
    </httpHandlers>
</system.web>

<system.webServer>
    <modules runAllManagedModulesForAllRequests="true">
        <clear/>
    </modules>
    <handlers>
        <clear/>
        <add path="*" name="MyHandler" type="MyHandler" verb="*" preCondition="integratedMode" resourceType="Unspecified" allowPathInfo="true" />
    </handlers>
</system.webServer>

尽管如此,当我访问任何 page.cshtml 页面时它仍然绕过我的通配符处理程序并尝试执行页面本身。

基本上我想删除 .cshtml handlers/buildProviders/preprocessing 的所有痕迹,这样我就可以自己提供 .cshtml 页面,有人知道我该怎么做吗?

Does anyone know how to disable the .cshtml extension completely from an ASP.NET Web Application?

In essence I want to hijack the .cshtml extension and provide my own implementation based on a RazorEngine host, although when I try to access the page.cshtml directly it appears to be running under an existing WebPages razor host that I'm trying to disable.

Note: it looks like its executing
.cshtml pages under the
System.Web.WebPages.Razor context
as the Microsoft.Data
Database is initialized. I don't even
have any Mvc or WebPages dlls
referenced, just System.Web.dll and a
local copy of System.Web.Razor with
RazorEngine.dll

I've created a new ASP.NET Web .NET 4.0 Application and have tried to clear all buildProviders and handlers as seen below:

<system.web>
    <httpModules>
        <clear/>
    </httpModules>
    <compilation debug="true" targetFramework="4.0">
        <buildProviders>
            <clear/>
        </buildProviders>
    </compilation>

    <httpHandlers>
        <clear/>
        <add path="*" type="MyHandler" verb="*"/>
    </httpHandlers>
</system.web>

<system.webServer>
    <modules runAllManagedModulesForAllRequests="true">
        <clear/>
    </modules>
    <handlers>
        <clear/>
        <add path="*" name="MyHandler" type="MyHandler" verb="*" preCondition="integratedMode" resourceType="Unspecified" allowPathInfo="true" />
    </handlers>
</system.webServer>

Although even with this, when I visit any page.cshtml page it still bypasses My wildcard handler and tries to execute the page itself.

Basically I want to remove all traces of .cshtml handlers/buildProviders/preprocessing so I can serve the .cshtml pages myself, anyone know how I can do this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

腻橙味 2024-11-24 07:30:05

如果您尝试关闭 ASP.NET 网页,您可以在应用程序设置中设置此标志:

<add key="webpages:Enabled" value="false" />

If you're trying to turn off ASP.NET webpages, you can set this flag in app settings:

<add key="webpages:Enabled" value="false" />
2024-11-24 07:30:05

您应该能够在 Application_Start 方法中注册您自己的自定义 ViewEngine。 Scott Hanselman 在博客中发布了一个使用移动设备自定义 ViewEngine 的示例,但这些想法应该与你想做的事情是一样的。

编辑(再次)David Fowler 建议

<add key="webpages:Enabled" value="false" />

我一直想知道这个设置的用途,但从未抽出时间去调查! :-)

You should be able to register your own custom ViewEngine in the Application_Start method. Scott Hanselman blogged a sample that uses a custom ViewEngine for mobile devices, but the ideas should be the same for what you're trying to do.

Edit (again): David Fowler suggests:

<add key="webpages:Enabled" value="false" />

I always wondered what that setting was for, but never got around to investigating! :-)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文