I've tried to add a MIME type to the webmatrix web.config file to run in Azure:
<system.webServer>
<staticContent>
<mimeMap fileExtension=".json" mimeType="application/json" />
</staticContent>
</system.webServer>
But I get a 500 (Internal Server Error) when trying to load a json file.
The site works locally.
Is there something else in Azure I need to do?
(Edit:)
All I have in web.config is:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.data>
<DbProviderFactories>
<remove invariant="System.Data.SqlServerCe.4.0" />
<add invariant="System.Data.SqlServerCe.4.0" name="Microsoft® SQL Server® Compact 4.0" description=".NET Framework Data Provider for Microsoft SQL Server Compact" type="System.Data.SqlServerCe.SqlCeProviderFactory, System.Data.SqlServerCe, Version=4.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91" />
</DbProviderFactories>
</system.data>
<system.webServer>
<staticContent>
<mimeMap fileExtension=".json" mimeType="application/json" />
</staticContent>
</system.webServer>
</configuration>
The bit without the MIME type was generated by webMatrix.
Error in console:
GET http://carlistings.azurewebsites.net/CarListings/data/cars.json?_dc=1364378861597&page=1&start=0&limit=25 500 (Internal Server Error)
UPDATE
The file doesn't change and is called by JavaScript from a Sencha Architect tutorial app.
{
"img" : "2004_Porsche_911_Carrera_type_997.jpg",
"manufacturer" : "Porsche",
"model" : "911",
"price" : 135000,
"wiki" : "http://en.wikipedia.org/wiki/Porsche_997",
"quality" : [{
"name" : "overall",
"rating" : 1
},{
"name" : "mechanical",
"rating" : 4
},{
"name" : "powertrain",
"rating" : 2
},{
"name" : "body",
"rating" : 4
},{
"name" : "interior",
"rating" : 3
},{
"name" : "accessories",
"rating" : 2
}]
}
UPDATE 2
I've noticed that running the app locally (where the app runs properly) the error log shows the cars.json file as application/json, whereas on the Azure server, it shows it as text/html.
It appears the Azure server is ignoring my web.config file with something else...
(I've enabled debugging in Azure but can't find a list of errors yet...)
The HTTP 500 is coming from something else.
I added exactly what you did in a new empty WebSite and the result is as expected.
URL to test: http://jsonp.azurewebsites.net/demo.json
Here is a fiddler trace from the request:
GET http://jsonp.azurewebsites.net/demo.json HTTP/1.1
User-Agent: Fiddler
Host: jsonp.azurewebsites.net
And the response is also as expected:
HTTP/1.1 200 OK
Content-Length: 30
Content-Type: application/json
Last-Modified: Wed, 27 Mar 2013 09:03:09 GMT
Accept-Ranges: bytes
ETag: "cc2c13e7c92ace1:0"
Server: Microsoft-IIS/7.5
.. aditional header omitted for readability
Date: Wed, 27 Mar 2013 09:03:52 GMT
{"title":"demo","count":10}
I suggest that you turn on all the possible logging and examine the error logs.
Most probably you define system.webServer twice, or something similar. Check out this SO question on how to enable logging.
UPDATE
After updating the question it is apparent that cars.json is not real static file. So the question is a bit messed. What type of script are you executing inside this "file" ?
UPDATE 2
Here is your json: http://jsonp.azurewebsites.net/demo.json
Apparently you are having issue with rest of the website setup. As I said - turn on all the logging and check the real error messages.
Related
Thank for reading my post.
I'm having an issue making my Website Application(Yii2) works correctly in Azure Web Apps. I've migrated my Yii2 Websites from an existing server to the Azure Web Apps. After lots of manipulation listed below, I’m able to access the Website.
The main theme loads successfully but throwing "404 Page not found
The requested page is missing, or the address has been changed" Error in the body and others links in the "Menu Bar" not working too. "The resource you are looking for has been removed, had its name changed, or is temporarily unavailable."
The Azure Resources are configured as below:
1 x App Service Plan : S1:1 (Windows Base)
1 x Azure Database for MySQL server
1 x App Service (The Web App)
App Service Application Setting:
.Net Framwork: v4.7
PHP Version: 7.0
Platform: 32bit
Migration Steps:
FTP all files/folder from htdocs in my existing server to my App Service Plan (\site/wwwroot)
Generate the SQL Table creation in PhpAdmin
Find and Replace ENGINE=InnoDB DEFAULT CHARSET=utf8; in the script
Connect to Azure Database for MySQL server, create new Schema and Run the Script
From Azure, KUDU Inferface browse (\site\wwwroot\config) and change the db.php to
<?php
return [
'class' => 'yii\db\Connection',
'dsn' => 'mysql:host=xxxx.mysql.database.azure.com;dbname=xxxxx',
'username' => 'xxxxxxx#xxxxxxxxxxxxxxxxxx',
'password' => 'xxxxxx',
'charset' => 'utf8',
];
Restart the Web App
Check the https://yourdomain.com/requirements.php (Passed without any Error)
"The resource you are looking for has been removed, had its name changed, or is temporarily unavailable" when trying to browse the new Web App.
KUDO PowerShell windows browse back to site/wwwroot and executed the following line of codes
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
php composer-setup.php
php composer.phar global require "fxp/composer-asset-plugin:^1.2.0"
Browse to the Directory (\site\wwwroot\web) and change index.php with the following line of codes:
if (!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] !== 'on') {
if(!headers_sent()) {
header("Status: 301 Moved Permanently");
header(sprintf(
'Location: https://%s%s',
$_SERVER['HTTP_HOST'],
$_SERVER['REQUEST_URI']
));
exit();
}
}
// comment out the following two lines when deployed to production
('YII_DEBUG') or define('YII_DEBUG', false);
defined('YII_ENV') or define('YII_ENV', 'prod');
require(__DIR__ . '/../vendor/autoload.php');
require(__DIR__ . '/../vendor/yiisoft/yii2/Yii.php');
$config = require(__DIR__ . '/../config/web.php');
(new yii\web\Application($config))->run();
From the Azure Portal / Web App / Application settinh, .change the default directory from site\wwwroot to site\wwwroot\web
Restart the Web App.
The home page them now loads successfully but with a 404 Error within the body and "The resource you are looking for has been removed, had its name changed, or is temporarily unavailable." when trying to access other pages in the header.
I also noted that I have 2 .htacss file
1x in my \site\wwwroot and 1x in my \site\wwwroot\web
Haved tried deleting them and configure a web.config file in (site\wwwroot\web) but still not working.
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="Redirect rquests to default azure websites domain" stopProcessing="true">
<match url="(.*)" />
<conditions logicalGrouping="MatchAny">
<add input="{HTTP_HOST}" pattern="^yoursite\.azurewebsites\.net$" />
</conditions>
<action type="Redirect" url="https://mysitename.azurewebsites.net/{R:0}" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
As Yii2 is not famous in Azure Web App, can't find a solution anywhere. Will appreciate if you can help along.
I'm in the process of migrating some applications from ASP.NET 5 beta7 to RC1. Using HTTPPlatformHandler I am able to run any of these ASP.NET 5 RC1 applications as the root of an IIS site. But they will not run as a subdir (right-click 'add application') of the site. The full response shows:
HTTP/1.1 404 Not Found
Content-Length: 0
Server: Kestrel
X-Powered-By: ASP.NET
Date: Tue, 24 Nov 2015 14:59:04 GMT
It isn't a permissions issue, as the route is served successfully when the app is the root of the site and using the same app pool.
The app pool is configured for 'no managed code' and integrated pipeline.
The web.config for the root application looks like this:
<configuration>
<system.webServer>
<handlers>
<add name="httpplatformhandler" path="*" verb="*" modules="httpPlatformHandler" resourceType="Unspecified" />
</handlers>
<httpPlatform processPath="..\approot\web.cmd" arguments="" stdoutLogEnabled="false" stdoutLogFile="..\logs\stdout.log" startupTimeLimit="3600"></httpPlatform>
</system.webServer>
</configuration>
For the sub application I've had to remove the httpplatformhandler handler to avoid the error "Cannot add duplicate collection entry of type 'add' with unique key attribute 'name' set to 'httpplatformhandler'".
Now that we have to use kestrel/httpplatformhandler, is it possible to run as an application under a site?
This problem started with beta8 and is still an open issue in RC1. See ASP.NET IIS Integration issue #14. "That fix is coming." says #davidfowl. "This is a workaround until the fix is available. We're working with the httpPlatformHandler team to fix bugs found in beta8 and rc1."
The workaround is to map the IIS app path in Startup.Configure like this:
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
app.Map("/MyAppPath", (myAppPath) => this.ConfigureMyAppPath(myAppPath, env));
}
public void ConfigureMyAppPath(IApplicationBuilder app, IHostingEnvironment env)
{
// the actual Configure code
}
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?
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>
Intermittently, a virtual directory under the its website is unable to access the web.config. It's as if the virtual directory is not properly inheriting the web.config file from it's parent website. The issue is not reproducible all the time and when we get this issue all we need to do is recycle the app pool for the website and everything works fine.
Somewhere in the code (from the virtual directory) we are doing something like this :-
string MembershipProvierName =
(WebConfigurationManager.GetSection("system.web/membership") as MembershipSection).DefaultProvider;
and the web.config on the parent website :-
<system.web>
<membership defaultProvider="SomeProvider">
<providers>
<add name="SomeProvider" enableSearchMethods="true" enablePasswordReset="false" requiresQuestionAndAnswer="false" type="SomeRandomType" defaultUsername="aaa#bbb.com" />
</providers>
</membership>
...
</system.web>
and the exception :-
System.Web.HttpException, System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a Message : Source : System.Web Help link : WebEventCode : 0 ErrorCode : -2147467259 Data : System.Collections.ListDictionaryInternal TargetSite : System.String GetPhysicalPath(System.Web.VirtualPath) Stack Trace : at System.Web.CachedPathData.GetPhysicalPath(VirtualPath virtualPath) at System.Web.CachedPathData.GetConfigPathData(String configPath) at System.Web.HttpContext.GetFilePathData() at System.Web.HttpContext.GetSection(String sectionName)
This is happening in production environment and not reproducible in any other environment. In prod also, this is quite intermittent. In prod the IIS version is most likely 6.0.3790.3959. By any chance anybody knows If this is an IIS issue?