在ASP.NET Web应用程序中禁用Razors默认.cshtml处理程序 [英] Disable Razors default .cshtml handler in a ASP.NET Web Application

查看:209
本文介绍了在ASP.NET Web应用程序中禁用Razors默认.cshtml处理程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

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

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.

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

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

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

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>

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

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

基本上我想删除所有.cshtml handlers/buildProviders/preprocessing的痕迹,以便我自己为.cshtml页面提供服务,任何人都知道我该怎么做?

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?

推荐答案

如果您要关闭ASP.NET网页,则可以在应用设置中设置以下标志:

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

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

这篇关于在ASP.NET Web应用程序中禁用Razors默认.cshtml处理程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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