ASP.NET web application Web.config staticContent error IIS server - asp.net

I have the following defined on my Web.config file so that it will serve json files.
<system.webServer>
<staticContent>
<mimeMap fileExtension=".json" mimeType="application/json" />
</staticContent>
This works fine when running the application with Visual Studio, but when using this project with IIS server it will make it not deliver any css or javascript files leaving html alone. Commenting out the lines fixes it.
Is that the wrong way of telling the server to accept json file requests? Otherwise, why does it create a conflict on IIS?

Related

How to remove WebDAV module in WebAPI core?

I have created a simple WebAPI using .Net Core 2.2. While I use POSTMAN to hit the action method with PUT HttpVerb, I get
405 - Method not allowed
message. While I checked for this online, the suggestion was to remove the WebDAV module from the Web.config. But in the .Net Core WebAPI, there is launchSettings.json and appsettings.json for the configuration.
Kindly help me as to how to set the setting in either of the aforementioned config files to remove the WebDAV module.
I'm new to .Net Core.
I tried to create a Web.Config and used the below code to remove the WebDAV module, but no luck
<system.webServer>
<modules runAllManagedModulesForAllRequests="false">
<remove name="WebDAVModule" />
</modules>
</system.webServer>
I haven't done this is WebAPI without using .Net Core. The request from POSTMAN is expected to hit the PUT method.
Kindly help.
How to convert this setting to JSON format for appSettings.json
We had the same problem; PUT was enabled in IIS Express, which was our testing environment, and WebDAV was installed on the production environment which disabled PUT and DELETE verbs. This resulted in an error on the production server: 405 HTTP verb used to access this page is not allowed
This is solved by adding a web.config configuration file to the project that disables WebDAV -- don't try to add this to the app.settings JSON file.
web.config file below:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.webServer>
<modules runAllManagedModulesForAllRequests="false">
<remove name="WebDAVModule" />
</modules>
</system.webServer>
</configuration>

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.

Styles from dotless files not used

We have a website that makes use of .less files (the pre-compiler dotless has been installed using nuget), however the .less files are not handled as css files.
When trying to view the website in firefox, the console gives use the following error:
The stylesheet http:// website/css/init.less was not loaded because its MIME type, "application/octet-stream", is not "text/css".
Our dotless file is trying to import more files:
#import "imports";
..
But even replacing this text with css code, the styles are still not applied. But if I go to that file in Visual Studio, it is displaying all the css from the files that are imported.
If you're using the dotLess handler to process and serve your .less files on the fly (which is fine for debugging, but you might want to consider pre-compiling for release), you need to ensure that you also send them down with the correct mimetype.
You can do this either at the server level in IIS Admin (if you're likely to using this for multiple sites on the machine), or at the local site level via the web.config - note that you can't do both, IIS will complain that there are multiple entries for the file extension.
To do this in the web.config, within the <configuration><system.webServer> element add the following elements:
<staticContent>
<mimeMap fileExtension=".less" mimeType="text/css" />
</staticContent>
Obviously, if you've already got some mimemap entries, just add the mimemap there.
This will ensure that IIS claims that the .less files served from the handler as CSS rather than the default application/octect-stream.
If that's still not serving them as processed, there are a couple of other things you'll need to check:
Ensure that the handler is correctly registered in both the <system.webserver><handlers> and <system.web><httpHandlers> sections (depending on the version of IIS you're using:
<add name="dotless" path="*.less" verb="GET" type="dotless.Core.LessCssHttpHandler,dotless.Core" resourceType="File" preCondition="" />
and
<add path="*.less" verb="GET" type="dotless.Core.LessCssHttpHandler, dotless.Core" />
Ensure that IIS is configured to send all requests through the ASP.NET handlers configured in step 1. By default, .less files are probably being considered "static files" and will only be handled by the StaticFileModule.

How to set Allow Parent Paths in IIS Express Config using asp directive

This is a continuation of a answered question in the following link:
How to set Allow Parent Paths in IIS Express Config
I am running a classic asp web site in IISexpress.
The same web site is also used in IIS 7.5 in a w7 pro and works fine enabling the parent paths in the IIS configuration of the web but trying to use the web.config in IISExpress does not work
The problem that I am experiencing is that in the suggested web.config in order to enable the parent paths:
<configuration>
<system.webServer>
<asp
enableParentPaths="true"
bufferingOn="true"
errorsToNTLog="true"
appAllowDebugging="true"
appAllowClientDebug="true"
scriptErrorSentToBrowser="true">
<session allowSessionState="true" />
<cache diskTemplateCacheDirectory="%TEMP%\iisexpress\ASP Compiled Templates" />
<limits />
</asp>
</system.webServer>
</configuration>
I get a 500 error every time that I try to use any asp tag
If I remove the asp tag it all works fine,
Anybody has a clue?
TIA
You have not read carefully. The configuration file that mentioned isn't web.config. It is applicationHost.config. As a shotcut:
Press Win+R
type
notepad "%userprofile%\Documents\IISExpress\config\applicationhost.config"
hit ⏎. This will open the host configuration file with notepad. You need to find your web site's section. It's something like <location path="YourSiteName"> ... </location>. Look inside that node, find the <asp> section and change with yours. Finally, don't forget to remove the asp section from web.config.

How to enable IIS to serve extension through web.config

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.

Resources