I faced a strange issue, while having the second load of the page, bundle must be retrieved from Cache, right? But what I see is that some long operations is performed on each request. Perhaps someone knows how to figure this out? Where does the figure of 250 ms comes from for the CSS bundle of 7kb?
Bundles are from default MVC 4 project.
The screens are below:
I finally found the reason. Actually MVC treats the bundle url as the real url and try to launch all the modules that specified in Web.config by default.
Adding new config section
<location path="~/Content/themes/base/css">
<system.webServer>
<handlers>
<clear/>
</handlers>
</system.webServer>
</location>
solved the problem and now additional time does not spend on each request.
Related
I'm having some problems with deploying my application and while troubleshooting, I came across the Web.Config file in the Views folder. In an attempt to narrow down the possibilities of sources to my problem, I tried to find out the purpose of that ~Web.Config` file but can't really find much information.
So basically my questions are:
What does the Web.config file do in the Views folder of a MVC project?
Is it required?
In Asp.Net webforms, I believe that to use a separate web.config file in a folder, that folder has to be set as a virtual folder in IIS. Is this the case in MVC (i.e. does the Views folder need to be configured as a virtual folder)?
No, you do not need to configure a virtual folder because of this extra web.config file.
The web.config file exists in the Views folders to prevent access to your views by any means other than your controller. In the MVC design pattern, controllers are supposed to route requests and return a rendered view to the calling client.
In other words, your view at www.mydomain.com/MySuperController/AwesomeAction1/SweetPage.aspx should not be directly accessible.
If you peek at the web.config file it actually registers the HttpNotFoundHandler to all paths and verbs:
<add path="*" verb="*" type="System.Web.HttpNotFoundHandler"/>
Or, in IIS 7 it might look like
<add name="BlockViewHandler" path="*.aspx" verb="*"
preCondition="integratedMode" type="System.Web.HttpNotFoundHandler"/>
It configures the compiler for the views such as importing namespaces and makes the views folder return a 404.
The web.config file in the views folder is to do some specialized settings you want to apply to pages inside the view folder.
Like config settings like: connection string / appsettings etc.
but that will be applicable to only that folder and rest of the project will pick up the settings from web.config present at the root.
Specially when you use concept of area there will be separate folder for each area containing separate web.cfg file where you can apply separate settings for each area.
That's if you want to override something mentioned in the upper web.config, i.e. if you want to customize something within the scope of the Views folder.
I have two applications setup in IIS7.5. MVC 3 is installed. One application serves Razor files fine. A separate application was recently created that will not serve Razor files. I get the following error when accessing the file using the full filename (file.cshtml):
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.
When trying to access the file without an extension (/path/file/) I get a 404 error.
I have searched for this problem but haven't found a solution where it works with one application but not another on the same server.
Both applications are using the same App Pool.
Web.Config files are identical.
Do both sites have a CSHTML file in the root of the application? Since the WebPages framework (which is what is used when you request a CSHTML file directly) has a significant impact on your site's performance if you aren't using it, we only start it if there's a CSHTML file in the root folder of your site (i.e. ~/Foo.cshtml). If you don't have any CSHTML files in your root, you can also add a web.config entry to set an appSetting:
<configuration>
<appSettings>
<add key="webpages:Enabled" value="true" />
</appSettings>
</configuration>
If you're confused by my answer, it would help if you edited your question to add information about the file layout of the two apps. Then I can add some concrete examples to try and clarify things :).
Hope that helps!
In the web.config, I've set maxRequestLength to 102400. When I upload a 65M file, it redirects me to a 404 error page, but it is normal in asp.net. This is the current setting:
<httpRuntime requestValidationMode="2.0" maxRequestLength="102400"/>
If you try to upload a small file, its work? I think this kind of error isn't related with maxRequestLength. Verify your Upload Action, or write here for us.
My project has a feature to override views and content, if they exist, from a themes folder. The path to the themes folder will vary by site, so my folder structure looks like this:
Themes\
SiteA\
Content\
Images\
logo.png
screen.css
Views\
Home\
Index.cshtml
I am able to successfully override the default view with the site's custom one. However I am unable to access anything in the Content folder for the theme. If I access the file directly at http://localhost:port/Themes/SiteA/Content/screen.css, the resource cannot be found. I also get this error when I try to access anything in the images folder. A co-worker was able to do this for a separate project last year, but I cannot find any notable changes to web.config or other files that would make it work. Any help is appreciated!
A co-worker found the problem. When I setup the Themes folders, I copied web.config from Views, which has this option:
<add name="BlockViewHandler" path="*" verb="*" preCondition="integratedMode" type="System.Web.HttpNotFoundHandler" />
We changed the path attribute's value from * to *.cshtml and the files are now accessible.
I'm not able to comment so I'm posting here. Do you have a route that matches the url? Try the RouteDebuger to see what route is hit.
Have you checked the permissions on the underlying folder in the file system? In my experience that's often the cause of being unable to access a resource through a URL - the credentials used by the web site may not be granted access to the underlying resource
I'm trying to implement roles in my site.
There are several projects in the solution, one of which is a web application.
In that web application, I'm trying to use WSAT to create three roles. There are many folders for the application. I've used WSAT to define role based access rules for each folder.
However, when I debug and navigate to those pages, they do not redirect to a login and show me the protected page.
There are web.config files in each folder.
Why would the system not enforce these rules?
My web.config file has:
<roleManager enabled="true" defaultProvider="AspNetSqlProvider" />
I've tested the connections in WSAT and they work.
Any ideas?
try
<roleManager enabled="true"/>
Also, please edit your question to provide the web.config from one of your subdirectories.
Yes, I fixed the problem.
A previous developer had cleared all the HTTP modules. Since all the modules were disabled, the authentication module wasn't part of the asp.net pipeline.