How to enable IIS to serve extension through web.config - asp.net

I'm having some trouble with a website on a webhotel. It will not serve *.mp4 files - I simply get error 404.
Had I access to the server I'd add the mimetype in IIS, however I haven't :-(
The webhotel said they wouldn't customize their IIS for one customer, so I should enable it in my web.config instead.
Now my question is: how do I do this ?
I'm aware of the FileExtensions tag, but its default behaviour is to allow all extensions, so I doubt that's what they meant.
They're a bit slow to elaborate on these kinds of things, therefore I ask here :-)

<configuration>
<system.webServer>
<staticContent>
<mimeMap fileExtension=".mp4" mimeType="video/mp4" />
</staticContent>
</system.webServer>
</configuration>
Obviously, don't repeat any sections that are already in your web.config just add the children in the appropriate places.

Related

Web.config in subdirectory causing 500 internal server error

I have a working ASP.NET web application. I'm trying to enable SSL using Let's Encrypt and to do this my shared web host host (A2) adds a web.config in the .well-known/acme-challenge directory. (All this web.config does is to bind extensionless files to plain text).
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<staticContent>
<mimeMap fileExtension="." mimeType="text/plain" />
</staticContent>
</system.webServer>
</configuration>
The issue is the mere presence of a web.config in a subfolder seems to cause any request for resources from this folder to fail, returning a 500 error. I've even tried a completely empty web.config in this folder and that still causes 500 errors. My understanding is that ASP.NET should support additional web.configs in subfolders but I have no idea why it isn't working.
I have a web.config in my root folder with the proper binding for extensionless files but the A2 Let's Encrypt tool insists on adding its own into the subfolder. I do not have any attributes preventing overridding in this web.config.
I've searched extensively for how to fix this but most of the solutions I see require changing IIS configuration. As this is a shared web host, I have extremely limited control over IIS, so that is not a viable option.
Can you add this to your root web.config:
<customErrors mode="Off" />
... which will then result in some more error information included in the 500 response? That could provide some hints as to how to properly fix this.

EPIserver no CSS for the UI Admin section

After moving a EPI6 site to my local machine and reconfiguring it for IIS7.5 (instead of IIS6) i have a problem.
The UI Admin/Edit backend has no CSS. I suspected this was due to the virtual path mapping and i found that they where all mapped to %ProgramFiles% but on my local machine EPI is installed on %ProgramFiles(86)%. So i changed it and made sure all physical paths worked. They did.
So i felt smart and expected the CSS to load properly but no change happened.
I have tried ctrl F5 to see if its a caching problem, i have restarted the IISExpress. But still no CSS.
Any tips on something i might have forgotten?
Check using Firebug Net-tab or equivalent F12 web browser tool to see exactly which paths don't respond correctly.
Check permissions on disk for the Program Files directories in questions.
Compare Web.config to a default EPiServer IIS7 web.config to see that you have all handlers in the correct place.
I solved this.
It was not a problem of rights, but rather a configuration error. When uppgrading fom using IIS6 to IIS7.5 i forgot changing in the Web.Config:
IIS6 version
<location path="App_Themes/Default" />
to:
IIS7.5 version
<location path="App_Themes/Default">
<system.webServer>
<handlers>
<clear />
<add name="wildcard" path="*" verb="*" type="EPiServer.Web.StaticFileHandler, EPiServer" />
</handlers>
</system.webServer>
</location>

Custom HttpHandler never running

Forgive me if this is basic. I've never made one before and can't seem to figure out why it's not working. I wrote a little handler to do some parsing on CSS files. I added this:
<system.web>
<httpHandlers>
<remove verb="*" path="*.css"/>
<add verb="*" path="*.css"
type="MyNameSpace.CssRelativePathHandler,CssRelativePathHandler" />
</httpHandlers>
</system.web>
Nothing ever happens. CSS files get parsed normally. No errors, nothing, the code never runs. What am I missing? Shouldn't this cause the handler to be used when *.css files are served? (I added the "remove" later, since I thought perhaps I needed to do that to override a built-in hander, again, no difference either way).
This is IIS 6. I added the IIS 7 code anyway (after searching for answers) but makes no difference.
<system.webServer>
<handlers>
<add name="CssHandler" verb="*" path="*.css"
type="MyNameSpace.CssRelativePathHandler,CssRelativePathHandler" />
</handlers>
</system.webServer>
You need to configure IIS6 to send requests for .css files to ASP.Net.
Had you been using IIS7, your <system.webServer> element would have done that for you, but IIS6 predates this.
For IIS 6 you need to have to tell it to send *.css files to ASP.NET.
Launch IIS Manager
Right-click on Default Web Site
Click on the Home Directory tab
Under Application Settings click on Configuration...
Add a new association for .css and map it to .NET executable:
C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll
It sounds like you need to configure IIS to enable ASP.NET to execute the .css extension.
Phil Haack has a walkthrough on doing that (just replace .mvc with .css under the heading "Mapping .mvc to ASP.NET"):
http://haacked.com/archive/2008/11/26/asp.net-mvc-on-iis-6-walkthrough.aspx
Or you can set up a wildcard mapping in IIS 6:
http://www.microsoft.com/technet/prodtechnol/WindowsServer2003/Library/IIS/5c5ae5e0-f4f9-44b0-a743-f4c3a5ff68ec.mspx?mfr=true
I'd recommend going with the first method as doing the wildcard approach will send all requests to ASP.NET - so it has a more overhead.
PS: Further down Phil's post, he also lists "IIS6 Extension-less URL" and also covers the wildcard mapping method.

ASP.NET 3.5 application with multiple web.config files (IIS 7)

We are working on a web application that creates more web applications.
Each web application will have to get a Url Rewrite rule (URL REWRITE MODULE 2.0).
As far as I know, there's no way to add such rules without modifying the web.config file (am I right??).
So my plan was to work with multiple web.config partial files. One main .config file, and lots of .config files per application (every file will contain it's web application url rewrite rules).
This way sounds a little bit messy, but I can't think of anything else, and suggestions will be welcomed.
So is it possible to use very-multiple web.config files for the root application?
Thanks in advance, Gal.
This following Tag will do the trick.
The absence of this tag was the main reason for my problem when i using with two web.config files for my two different application running in my website.
**<location path="." inheritInChildApplications="false">**
<system.web>
<!-- ... -->
</system.web>
**</location>**
Every application must have a full web.config and not partial, exept if you go with net 4
The trick is to use a lot the remove command on the other inside web.config and remove the parents setting that must not used on this.
For example if on the main root you have the a module that you do not won to use it on the other trees, you use the remove command on all other web.config to remove it. Especial the modules that are on one Bin and not on an other directory bin.
<httpModules>
<remove name="TheHttoModuleNotNeedHere" />
<remove name="AnonymousIdentification" />
... add here your other modules for that directory...
</httpModules>
The remove command is working for almost all sessions on config.
You can do make it work, I have done it, but its a lot of work to find all the conflicts/unnecessary configs and remove it.
For some other session there also the clear command. For example on role Manager you can clear all and add new.
<roleManager enabled="true" ...>
<providers>
<clear />
<add name="MyName" ... type="System.Web.Security.SqlRoleProvider" />
</providers>
Hope this help as tips to make it work.

What is wrong with my MVC application?! (500 on Content and Scripts)

For anything under the Scripts or Content folders in my ASP.NET MVC application, I am getting the following error:
The page cannot be displayed because an internal server error has occurred
That's the response in its entirety (excepting the headers) - nothing else. I am hosting this on GoDaddy, and have not had problems with this application before. What did I do to screw this up?! Working on 4 hours of sleep isn't helping matters...
This would be appropriate here:
"It takes considerable knowledge just to realize the extent of your own ignorance."
-Thomas Sowell
So, when struggling to get a Flash-based, JavaScript-configured component to work in my web app, I added a staticContent node to my web.config, with a mimeMap node as a child:
<configuration>
...
<system.webServer>
...
<staticContent>
<mimeMap fileExtension=".mp4" mimeType="video/mpeg" />
</staticContent>
</system.webServer>
</configuration>
When I commented-out the entire staticContent node, everything worked just fine. I didn't know that adding a mimeMap here would cause all of the default mimeMaps (specified within the server's ApplicationHost.config) to be overridden, because that seems to be exactly what is going on...Then again, I am merely guessing - either way, not very easy to figure out.
Thank you to everyone that responded, I appreciate it!
In your web.config file, find the customErrors section and change mode to Off.
<customErrors mode="Off">
</customErrors>
Changing that will give you a more descriptive error.
I had the same issue when upgrading to a newer version of IIS, though with a different mime type. As you also surmised, I believe the new version must already have the type registered (or the host did it at the machine level). I solved it by putting "remove" before the "add" - all my content started showing up again. I would think this would prevent having to modify the config between dev and prod.
<staticContent>
<remove fileExtensions=".mp4" />
<mimeMap fileExtension=".mp4" mimeType="video/mp4" />
</staticContent>
This has been edited to replace video/mpeg with video/mp4. /mpeg still worked for me, but apparently mp4 is recommended.
Can you turn off Simple error messages?
Perhaps you could try putting
routes.IgnoreRoute("Scripts");
routes.IgnoreRoute("Content");
in your route register?
Also make sure that if you are using the built-in authentication, you have this bit in your web.config, though I think it isn't your problem:
<location path="public">
<system.web>
<authorization>
<allow users="*"/>
</authorization>
</system.web>
</location>
Hmm, do you have any control of IIS on that hosting? Maybe they have a wildcard mapping interfering. That's happened to us before with site minder.
Download Phil Haack's Route Debugger, then try navigating to one of the Scripts. You might be catching them in your routes.

Resources