Allow loading of JSON files in Visual Studio Express 2013 for Web - iis

I have the problem, that the IIS from Visual Studio Express 2013 for Web doesn't allow the loading of *.json files. When trying to load a *.json file I get a 403 Forbidden and a help page how to configure the IIS allow the loading of JSON files, but don't know what to do with this information / where the IIS is even located.
This is the error page:
HTTP Error 404.3 - Not Found The page you are requesting cannot be
served because of the extension configuration. If the page is a
script, add a handler. If the file should be downloaded, add a MIME
map.
Most likely causes: It is possible that a handler mapping is missing.
By default, the static file handler processes all content. The feature
you are trying to use may not be installed. The appropriate MIME map
is not enabled for the Web site or application. (Warning: Do not
create a MIME map for content that users should not download, such as
.ASPX pages or .config files.) If ASP.NET is not installed.
Things you can try: In system.webServer/handlers: Ensure that the
expected handler for the current page is mapped. Pay extra attention
to preconditions (for example, runtimeVersion, pipelineMode, bitness)
and compare them to the settings for your application pool. Pay extra
attention to typographical errors in the expected handler line. Please
verify that the feature you are trying to use is installed. Verify
that the MIME map is enabled or add the MIME map for the Web site
using the command-line tool appcmd.exe. To set a MIME type, run the
following command in the IIS Express install directory: appcmd set
config /section:staticContent
/+[fileExtension='string',mimeType='string'] The variable
fileExtension string is the file name extension and the variable
mimeType string is the file type description. For example, to add a
MIME map for a file which has the extension ".xyz": appcmd set config
/section:staticContent /+[fileExtension='.xyz',mimeType='text/plain']
Warning: Ensure that this MIME mapping is needed for your Web server
before adding it to the list. Configuration files such as .CONFIG or
dynamic scripting pages such as .ASP or .ASPX, should not be
downloaded directly and should always be processed through a handler.
Other files such as database files or those used to store
configuration, like .XML or .MDF, are sometimes used to store
configuration information. Determine if clients can download these
file types before enabling them. Install ASP.NET. Check the failed
request tracing logs for additional information about this error. For
more information, click here.
Detailed Error Information: Module StaticFileModule Notification
ExecuteRequestHandler Handler StaticFile Error Code 0x80070032
Requested URL http: //localhost:64107/Settings/Settings.json
Physical Path D:\GIT\RepoP_Paneon\Settings\Settings.json Logon
Method Anonymous Logon User Anonymous Request Tracing Directory
C:\Users\stefank\Documents\IISExpress\TraceLogFiles\REPOP_PANEON
More Information: This error occurs when the file extension of the
requested URL is for a MIME type that is not configured on the server.
You can add a MIME type for the file extension for files that are not
dynamic scripting pages, database, or configuration files. Process
those file types using a handler. You should not allows direct
downloads of dynamic scripting pages, database or configuration files.
View more information ยป

After some more googling, and experimenting I found out, that you have to define IIS settings in the Web.config.
After adding the following configuration:
<system.webServer>
<staticContent>
<mimeMap fileExtension=".json" mimeType="application/json" />
</staticContent>
</system.webServer>
it works like a charm.
Full setup file example:
<?xml version="1.0"?>
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0"/>
</system.web>
<system.webServer>
<staticContent>
<mimeMap fileExtension=".json" mimeType="application/json" />
</staticContent>
</system.webServer>
</configuration>

Better add remove tag in case future IIS has build in json support. This is my web.config section of mimeMap.
<system.webServer>
<staticContent>
<remove fileExtension=".woff" />
<remove fileExtension=".woff2" />
<remove fileExtension=".json" />
<mimeMap fileExtension=".woff" mimeType="application/x-font-woff" />
<mimeMap fileExtension=".woff2" mimeType="application/font-woff2" />
<mimeMap fileExtension=".json" mimeType="application/json" />
</staticContent>
<system.webServer>

Open CMD with administrator privilages.
Go to:
cd C:\Program Files\IIS Express
or
cd C:\Program Files (x86)\IIS Express
Run command:
appcmd set config /section:staticContent /+[fileExtension='JSON',mimeType='application/x-javascript']

We may need to distinguish the Visual Studio development environment (with IIS Express) from local IIS and a remote server (like Azure WebSites). To specifically target IIS Express, for example, we edit %USERPROFILE%\Documents\IISExpress\config\applicationhost.config under system.webServer/staticContent:
<mimeMap fileExtension=".json" mimeType="application/javascript" />
I need to make this distinction because my local (intranet) IIS already has the JSON mime type defined. So when I deploy to Azure websites I use this transformation in Web.Release.config:
<system.webServer>
<staticContent>
<mimeMap fileExtension=".json" mimeType="application/javascript" xdt:Transform="Insert" />
</staticContent>
</system.webServer>

Related

Error starting application in .netcore

I'm getting the following error when navigating to my IIS published .netcore application:
I have set up my web.config file as so:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<!--
Configure your application settings in appsettings.json. Learn more at http://go.microsoft.com/fwlink/?LinkId=786380
-->
<system.webServer>
<handlers>
<add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModule" resourceType="Unspecified" />
</handlers>
<aspNetCore processPath="dotnet" arguments=".\KritnerWebsite.dll" stdoutLogEnabled="true" stdoutLogFile=".\logs\stdout" forwardWindowsAuthToken="false" />
</system.webServer>
</configuration>
Not sure if this warning is relevant or just outdated:
Severity Code Description Project File Line Source Suppression State
Warning The element 'system.webServer' has invalid child element 'aspNetCore'. List of possible elements expected: 'asp, caching, cgi, defaultDocument, directoryBrowse, globalModules, handlers, httpCompression, webSocket, httpErrors, httpLogging, httpProtocol, httpRedirect, httpTracing, isapiFilters, modules, applicationInitialization, odbcLogging, security, serverRuntime, serverSideInclude, staticContent, tracing, urlCompression, validation, management, rewrite'. KritnerWebsite D:\gitWorkspace\KritnerWebsite\src\KritnerWebsite\web.config 12 Build
The line in the web.config was as per the template, I just changed "false" to "true" for stdoutLogEnabled.
I have also created an empty folder in the root directory "logs" - I wasn't sure if this should get created automatically or not. Either way, nothing is being written to the logs, so I am not sure what to try next.
I have opened the solution in VS2015 on my host, compiled it and ran it successfully through commandline/localhost with dotnet run. This is running it in the production configuration, so pulling from my environment variables for insights key, and connection string. So I'm not sure why the site would run successfully on my host through dotnet run but not when published to IIS
How do I get further information on what the error is?
I'm not sure what exactly caused the logs to start correctly recording in ./logs... but they did. With the exception now being recorded I could see that my connection string I had set up in my Environment Variables was off.
Still not sure what caused the logs to not write out in order for me to determine this faster.
After updating my environment variable and running iisreset as per https://serverfault.com/questions/193609/make-iis-see-updated-environment-path-variable my website is now being served properly.

IIS 8.5 MVC5 Client Cache is ignored

TL;DR - I want the server (IIS 8.5) to return 304 not modified for the CSS and JS bundles.
I've been unable to get IIS 8.5 to honor the clientCache settings in web.config. No matter what I do, I can't seem to get it to cache the static content. This is a MVC5 app in VS2013. I've got all the static files in a folder "Assets".
The request looks like:
http://someserver/AppName/Assets/mainjs?v=FNj_9ZPAbYVAQsyDo2F8XUnWv5NQpY4iX2RGu4NpJ5g1
Attempt #1, place a new web.config in the Assets folder with the following:
<configuration>
<system.webServer>
<staticContent>
<clientCache cacheControlMode="UseMaxAge" cacheControlMaxAge="30.00:00:00" />
</staticContent>
</system.webServer>
</configuration>
Attempt #2: place this following configuration in the root web.config
<staticContent>
<clientCache cacheControlMode="UseMaxAge" cacheControlMaxAge="365.00:00:00" />
</staticContent>
Attempt #3: trying setting the cache using the location tag
<location path="Assets">
<system.webServer>
<staticContent>
<clientCache cacheControlMode="UseMaxAge" cacheControlMaxAge="365.00:00:00" />
</staticContent>
</system.webServer>
</location>
Here are the things I've tried in IIS 8.5 manager. Under the Default Web Site/TestApp
HTTP Requeset Headers, Set Common HTTP Headers, check "Expire Web Content" "After 365 Day(s)".
Apply the same setting to the "Assets" folder
I've tried these steps each on their own and all together and every other which way. No matter what, it won't add the max-age value to Cache-Control.
For each of these, the browswer returns 200 responses for the CSS and JS bundles. I cannot get the server cache the content coming from the Assets folder.
Cache-Control:private
Content-Encoding:gzip
Content-Length:22591
Content-Type:text/css; charset=utf-8
Date:Mon, 02 Feb 2015 21:49:49 GMT
Expires:Tue, 02 Feb 2016 21:49:49 GMT
Last-Modified:Mon, 02 Feb 2015 21:49:49 GMT
Persistent-Auth:true
Server:Microsoft-IIS/8.5
Vary:Accept-Encoding
X-AspNet-Version:4.0.30319
X-Powered-By:ASP.NET
Check the individual files of the bundle. What do the files look like when you turn off optimizations? After you register your Bundles make a call to :
BundleTable.EnableOptimizations = (!HttpContext.Current.IsDebuggingEnabled);
OR
BundleTable.EnableOptimizations = false;
It could be that each file is coming back with a not modified. Does the status change when you refresh while in a debug session?

How to allow web.config files as normal files and allow download IIS inside a virtual directory

I am working on a Unity 3D game which upon build for Windows generates game.exe and game_Data file and folder. The Game_Data folder contains a directory called **Game_Data\Mono\etc\mono\2.0**.
The directory files are shown in image.
The Browsers directory contains one file called Compact.browser.
The Current Scenario.
1. These game files are hosted on a server where IIS 7.5 is running.
The game resource files are served in virtual directory of the game website.
I've made few changes to the website's root web.config file so that all filetypes are allowed to download only in the game resources folder on server.
Yes, all file types including .html, .aspx, .xml, .config, .browser, .map etc are all downloading as normal files.
The problem
As you see the directory structure there is a web.config file inside the game resources folder. The file has nothing to do with website configuration but with the game (which is on client side after downloading).
As the files are served as individual files each file is downloaded separately. So when the client tries to download all files including the contents of the above folder.
Due to this web.config file, contents of the directory is not downloading. If I delete this web.config file all of the .aspx, .config, .map files are downloading. Also there are some other folders where many different files are downloading properly.
But this web.config file is also required for the game, and it is not allowing it be downloaded with other files too in the directory shown above.
I've tried to look into the solution. Found some hints to avoid inheritance in nested config files. But actually I want to completely treat this file as a normal file, not as a site configuration file.
I think you got my problem. Please let me know your suggestions. You can say adding Mime types. But actuall all of the file types are downloading including .config files. Except the file named web.config.
I'm having the same problem, and I think I found the solution: there is a way to tell IIS not to interpret web.config files.
To do this, modify the C:\Windows\System32\inetsrv\config\applicationHost.config file (I haven't found a way to do this in the IIS user interface), by specifying allowSubDirConfig="false" for the relevant <virtualDirectory> element:
<configuration>
<system.applicationHost>
<!-- ... -->
<sites>
<site name="Default Web Site" id="1">
<application path="/">
<virtualDirectory path="/" physicalPath="%SystemDrive%\inetpub\wwwroot" />
<virtualDirectory path="/Staging" physicalPath="C:\inetpub\wwwroot\Staging" allowSubDirConfig="false" />
</application>
<bindings> <!-- ... --> </bindings>
</site>
See http://www.iis.net/configreference/system.applicationhost/sites/site/application/virtualdirectory for the details.
The problem is, it still won't let you download the web.config file, it keeps returning a 404 - Not found, even after removing all handlers.
Edit - found the solution. The short answer is that in your web.config, you should clear the fileExtensions and hiddenSegments lists:
<system.webServer>
<security>
<requestFiltering>
<hiddenSegments>
<clear />
</hiddenSegments>
<fileExtensions>
<clear />
</fileExtensions>
</requestFiltering>
</security>
I've written a blog article about it that explains all the details.

Open .obj in Azure Error [duplicate]

I am using three.js for webGL to load .obj
but I have a problem when loading .obj in Windows Azure runnning Windows Server 2008
I using Google chrome browser and it gives the error below:
GET http://websiteaddress.net/webGL/obj/test.mtl 404 (Not Found)
even, I used their original source code to load .obj file it has the same error
and when i try to navigate other images file in the server i can preview it
eg: (website.net/images/test.gif) - i can see the test.gif image in the browser
but when i navigate to .obj, i receive error in the browser:
(eg : website.net/obg/test.obj)
404 - File or directory not found.
The resource you are looking for might have been removed, had its name changed, or is temporarily unavailable.
i can view my .obj locally but not when I put it in Azure!
can anyone helps me? Thanks!
[SOLVED] LOADING .OBJ (Wavefront) FILE IN WINDOWS HOSTING RETURN 404 ERROR [SOLVED]
As I was Working with Three.js and loading a .obj file works great for me in localhost but when running the files from the Windows Hosting it return 404 for the .obj file.
So, we need to add this lines to the web.config file of the project root folder (if you don't have the file in your project root folder then go ahead and create one. )
web.config
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<staticContent>
<mimeMap fileExtension=".obj" mimeType="application/octet-stream" />
</staticContent>
</system.webServer>
</configuration>
Place the web.config to correct location and Enjoy :)
You will need to add a mime type definition in your application to tell IIS how this file should be served. The mime map referred to in the error message should be defined in the web.config file. Here's an example.
<system.webServer>
<staticContent>
<mimeMap fileExtension=".mp4" mimeType="video/mp4" />
<mimeMap fileExtension=".m4v" mimeType="video/m4v" />
</staticContent>
</system.webServer>
Click on the link below for a full list of mime types:
Full list of mime types.
I found an answer to my problem, is because the file extension .obj is not yet map to the MIME type in my Azure server:
Check the link below on how to add it:
http://technet.microsoft.com/en-us/library/cc725608(v=ws.10).aspx
and you could check here for the MIME type:
http://filext.com/file-extension/OBJ
Once you have map .obj to MIME, you will have no problem to load it anymore! :)
I thought I should add what I ended up doing after finding this post. I'm using .mtl files for material (in addition to the .obj) for a THREE JS project. Since I'm using MTLLoader to get the materials as well (my models aren't just flat-color), I had to add the following line:
web.config
<!-- Instruct IISNODE to treate .obj+.mtl models as application/octet data -->
<configuration>
<system.webServer>
<staticContent>
<mimeMap fileExtension=".obj" mimeType="application/octet-stream" />
<mimeMap fileExtension=".mtl" mimeType="application/octet-stream" />
</staticContent>
</system.webServer>
</configuration>

IISExpress Log File Location

IISExpress writes log and configuration data to pre-determined location out of the box.
The directory is an "IISExpress" directory stored in a user's Documents directory.
In the directory is stored the following folders files underneath.
Config
Logs
TraceLogFiles
The location of my home directory is on a network share, determined by group policy
Currently we are encountering scenarios where visual studio locks up when stopping debugging Silverlight applications using IIS Express.
I was looking to change the location for the log & configuration data for IISExpress to see if this fixes the problem of visual studio locking up. Is it possible to change the default location of log & config files ?
1 . By default applicationhost.config file defines following two log file locations. Here IIS_USER_HOME would be expanded as %userprofile%\documents\IISExpress\.
<siteDefaults>
<logFile logFormat="W3C" directory="%IIS_USER_HOME%\Logs" />
<traceFailedRequestsLogging directory="%IIS_USER_HOME%\TraceLogFiles" enabled="true" />
</siteDefaults>
You can update above directory paths to change the log file locations.
2 . If you are running IIS Express from command line, you can use '/config' switch to provide configuration file of your choice. Following link may help you http://learn.iis.net/page.aspx/870/running-iis-express-from-the-command-line/
http://www.iis.net/configreference/system.applicationhost/sites/sitedefaults
<configuration>
<system.applicationHost>
<sites>
<siteDefaults>
<logFile
logFormat="W3C"
directory="%SystemDrive%\inetpub\logs\LogFiles"
enabled="true"
/>
<traceFailedRequestsLogging
enabled="true"
directory="%SystemDrive%\inetpub\logs\FailedReqLogFiles"
maxLogFiles="20"
/>
<limits connectionTimeout="00:01:00" />
<ftpServer serverAutoStart="true" />
<bindings>
<binding
protocol="http"
bindingInformation="127.0.0.1:8080:"
/>
</bindings>
</siteDefaults>
</sites>
</system.applicationHost>
</configuration>
I find web.config documentation is a messy. It is therefore better to provide a complete parent history than a floating snippet with the expectation that the reader naturally knows where it goes.
By default it will be in:
C:\Users\ user_name \Documents\IISExpress\Logs\

Resources