Resource cannot be found for content inside of theme folders - asp.net-mvc-3

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

Related

Can't download PDF from Umbraco media folder when using Azure blob storage

I've got an umbraco 8.14.1 site configured to use Azure blob storage for the media folder. Images work fine, but when I try to link to a PDF I get a 404 with the body
The resource you are looking for has been removed, had its name changed, or is temporarily unavailable.
If I replace the domain name of the site with the domain for the storage account I can view the PDF without issue, therefore the PDF is definitely in Blob storage.
Why aren't PDFs working but images are?
After upgrading Umbraco to latest 8.17.1 I noticed there was a line added to ~/Media/web.config
<add name="StaticFileHandler" path="*" verb="*" preCondition="integratedMode" type="System.Web.StaticFileHandler" />
Adding that in live fixed the issue without upgrading.

Reduce security from views folder MVC

In my views folder i want to use templates from jsrender but when i try to access anything from the Views folder it gives me 404 and 500 error as response not found.
What i just want to do is to access *. HTML file from the Views folder.
What should be the change in Web.Config of Views?
Thanks
What i just want to do is to access *. HTML file from the Views folder
No, you can't. The Views folder has a special meaning in ASP.NET MVC and there's a handler which forbids access to any file in it. You just have to put your templates somewhere else. A ~/Templates folder doesn't seem like a bad idea.

what is the purpose of web.config in views folder? [duplicate]

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.

Razor file loads in on application but not in the other on same server

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!

Access Rules created by WSAT are not enforced

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.

Resources