what is the function of webpages:Enabled in MVC 3 web.config
Asked Answered
H

3

214

I just started a new MVC 3 project. Can anyone tell me what

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

in my web.config file does?

Hemphill answered 3/2, 2011 at 12:24 Comment(2)
blogs.msdn.com/b/marcinon/archive/2011/01/13/…Selhorst
It would be helpful to note what happens if this is set and you attempt to browse a .chstml file. You get the error "This type of page is not served." Spent hours on this one :/ #12534105Hegumen
O
254

webPages:enabled with value false prevents .cshtml or .vbhtml files in the Views folder from being directly accessible from a web browser.

Oldtimer answered 3/2, 2011 at 12:27 Comment(5)
Actually it prevents them from being access directly regardless of where they reside in the application. In the views folder, in the root, in a different folder... doesn't matter you get the same error. The type of page you have requested is not served because it has been explicitly forbiddenFala
Isn't that what the "BlockViewHandler" configuration is for? What is the difference?Definitive
Sorry, running a Nancy project on Mono and this setting appeared via nuget. So I wonder, is this an IIS thing, and MVC 3 thing, or which part of the stack actually consumes this setting?Azaleeazan
I'm not allowed to see Views by default, but if i add this setting and set it to false, they are now parsed and attempted to be viewed.Megaphone
WebPages:Enabled enables it whether the value is true or false, the default value is null.Megaphone
L
29

According to documentation it prevents .cshtml and .vbhtml files from being accessed directly (www.myweb.com/views/home/index.cshtml for example)

Leffert answered 3/2, 2011 at 12:26 Comment(3)
I've been searching, but can't find a reference where this is explained. What I'd specifically like to know is what is the effect of omitting <add key="webpages:Enabled" value="???"> entirely. Is the default true or false?Maratha
So I've dug into the source code and the default value is actually null - meaning that webpages are enabled if application contains any *.cshtml or *.vbhtml files. Checking for files can be either disabled by setting this value to true or false. You can see for yourself here.Millibar
According to which documentation?Dependence
N
1

To allow Razor pages to be served, it's not enough to set <add key="webpages:Enabled" value="true" />. You also need to add the Microsoft.AspNet.WebPages package to packages.config using NuGet.

Neiman answered 2/2, 2017 at 20:5 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.