I cloned a client's Orchard CMS. The repository that I cloned did not contain the Media folder (this is good). So, a next step was to restore the Media/Default directory from a .zip backup. Now that I've restored that, browsing the to site gives a 404 error for all resources in the Media folder. Why?
Quick Fix
The /Media folder is missing its required Web.config file. Add it.
Media/Web.config
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<appSettings>
<add key="webpages:Enabled" value="false" />
</appSettings>
<system.web>
<httpHandlers>
<!-- iis6 - for any request in this location, return via managed static file handler -->
<add path="*" verb="*" type="System.Web.StaticFileHandler" />
</httpHandlers>
</system.web>
<system.webServer>
<staticContent>
<clientCache cacheControlMode="UseMaxAge" cacheControlMaxAge="7.00:00:00" />
</staticContent>
<handlers accessPolicy="Script,Read">
<!--
iis7 - for any request to a file exists on disk, return it via native http module.
accessPolicy 'Script' is to allow for a managed 404 page.
-->
<add name="StaticFile" path="*" verb="*" modules="StaticFileModule" preCondition="integratedMode" resourceType="File" requireAccess="Read" />
</handlers>
</system.webServer>
</configuration>
Details
Out-of-the-box, Orchard's Media folder contains a Web.config file. Since source control excluded the Media folder it also did not have its Web.config. In IIS 7+ Integrated Mode, the following config is required for serving static files, because the root Orchard.Web/Web.config file <clear/>s all handlers.
<add name="StaticFile"
path="*"
verb="*"
modules="StaticFileModule"
preCondition="integratedMode"
resourceType="File"
requireAccess="Read" />
Related
In debug mode my code is working fine.
window.BABYLON.SceneLoader.ImportMesh(
"",
"/assets/logo/3D/",
"logo.gltf",
that.scene,
function (meshes) { ..... });
My .gltf 3D asset is stored in public/assets/logo/3D with the name logo.gltf. I am using .NetCore as the web server.
Somehow whenever the loader requests .gltf file, it returns html. It suppose to return json (gltf). Image files like .jpg, '.png', etc... are fine.
I have specify the mime type for .gltf in my web.config file:
<system.webServer>
<staticContent>
<remove fileExtension=".gltf" />
<mimeMap fileExtension=".gltf" mimeType="model/gltf+json" />
</staticContent>
</system.webServer>
Here is the screenshot:
It retrieves as content-type: text/html. It suppose to be model/gltf+json.
How can I load the file safely?
You can configure ASP.NET Core to return correct Content-Type by adding your MIME type to file provider. In Startup add StaticFileOptions argument with extended content type provider to your app.UseStaticFiles() call
var provider = new FileExtensionContentTypeProvider();
provider.Mappings[".gltf"] = "model/gltf+json";
app.UseStaticFiles(new StaticFileOptions
{
ContentTypeProvider = provider
});
If you want to serve such static files via IIS you need to add a static file processing module before ASP.NET Core pipeline
web.config
<system.webServer>
<handlers>
<!-- added staticGltf handler to serve .gltf files -->
<add name="staticGltf" path="*.gltf" verb="*" modules="StaticFileModule" resourceType="File" requireAccess="Read" />
<add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModuleV2" resourceType="Unspecified" />
</handlers>
<aspNetCore you_config_here />
<staticContent>
<remove fileExtension=".gltf" />
<mimeMap fileExtension=".gltf" mimeType="model/gltf+json" />
</staticContent>
</system.webServer>
But in this case you might need to address possible issues with routes (such as ASP.NET Core is configured to search files in wwwroot folder but IIS will search in app root instead) and insufficient file permissions.
#Alexander answer is the correct answer. Here is my Startup file if anyone wants to know.
Inside the Configure method:
var provider = new FileExtensionContentTypeProvider();
provider.Mappings[".gltf"] = "model/gltf+json";
var staticFileOpt = new StaticFileOptions()
{
ContentTypeProvider = provider
};
app.UseStaticFiles(staticFileOpt);
app.UseSpaStaticFiles(staticFileOpt);
There is UseStaticFiles() and UseSpaStaticFiles(). I am using ReactJS as the SPA framework, that is why I need UseSpaStaticFiles() too.
I have an AngularJS application that I am trying to use an AJAX request to pull in a static file from a ASP.NET WebApi2 application running on IIS 8.5. Similar to the example below-
ng-include="http://server/Content/icon.svg"
If I navigate to that URL in the browser, IIS happily serves that file as a static file. However, when I use an AJAX request, Angular attempts an OPTIONS request first, since it is CORS request, and IIS throws a 405 Method Not Allowed.
I have tried adding these headers to the static Content folder in the web site-
However this made no difference. Also, the IIS server does not have WebDAV installed, which is a thing I have seen around as something that could cause issues.
I had an IIS site with a virtual directory from which I serve my static files.
In order to do CORS from the browser, what I did was configuring the "En tetes de réponses HTTP" of the site, which in english should be something like "HTTP Response Headers".
There I added a new header named "Access-Control-Allow-Origin" with value "*".
From this moment, I can use static files in XHR.
My actual problem was serving OpenStreetMap tiles to a file:///c/xxx/index.html and the error in chrome was
Image from origin 'http://myhost' has been blocked from loading by Cross-Origin Resource Sharing policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'null' is therefore not allowed access.
This works for me for accessing .png files in a subdirectory under forms authentication. You should be able to change the extension.
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.web>
<authorization>
<deny users="?" />
</authorization>
</system.web>
<system.webServer>
<staticContent>
<mimeMap fileExtension=".*" mimeType="image/png" />
</staticContent>
<handlers>
<clear />
<add name="StaticFile" path="*" verb="*" type="" modules="StaticFileModule,DefaultDocumentModule,DirectoryListingModule" scriptProcessor="" resourceType="Either" requireAccess="Read" allowPathInfo="false" preCondition="" responseBufferLimit="4194304" />
</handlers>
</system.webServer>
</configuration>
What if you add the OPTIONS as a verb for the Access-Control-Allow-Methods As answered in this question.
<system.webServer>
<httpProtocol>
<customHeaders>
<add name="Access-Control-Allow-Origin" value="*" />
<add name="Access-Control-Allow-Methods" value="GET,PUT,POST,DELETE,OPTIONS" />
<add name="Access-Control-Allow-Headers" value="Content-Type" />
</customHeaders>
</httpProtocol>
</system.webServer>
If you want to serve static files to the public internet without any authorization you can set your CORS polity to:
Allow GET request
From any Origin
Allow all request Headers
Allow the OPTIONS reply to be cached for 24h
Internet Information Server this can be configured with the following IIS configuration for your site
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<httpProtocol>
<customHeaders>
<add name="Access-Control-Allow-Methods" value="GET,OPTIONS" />
<add name="Access-Control-Allow-Origin" value="*" />
<add name="Access-Control-Allow-Headers" value="*" />
<add name="Access-Control-Max-Age" value="86400" />
</customHeaders>
</httpProtocol>
</system.webServer>
</configuration>
I used ` RouteTable.Routes.MapPageRoute for my pages in website
same as
RouteTable.Routes.MapPageRoute(1,
"~/LNG/WebSites/Vission/vissions.aspx","vission");
RouteTable.Routes.MapPageRoute(2,
"~/LNG/WebSites/Loss/LossCiculars.aspx","Loss Circular");
`....
but this worked for some page .
i have an error for other page http 404
in web.config i added this line
<system.webServer>
<modules runAllManagedModulesForAllRequests="true">
<remove name="UrlRoutingModule-4.0" />
<add name="UrlRoutingModule-4.0" type="System.Web.Routing.UrlRoutingModule" preCondition="" /> </modules>
</system.webServer>
Note : this code worked correctly when i have run project in v.s.
help me plz if you can
thanks
Our Team is building a C# project with a Silverlight module. We deploy to a Windows 2008 with IIS 7. I’m trying to Programmatically Expire the HTTP Response Headers Associated with a Folder called ClientBin immediately. I know how to do it manually through IIS Manager. ( Basically, I go to the HTTP Response Headers Section of the folder or file that is of interest, and then I use "Set Common Headers...." to expire immediately.) However, we will be Redeploying to IIS a number of times, and I want to ensure that it is programmatically done because it’s a headache to keep Reconfiguring all the time.
Should I do it from the C# code of my project or is it better practice to do it using WMI scripting?
#kev and #jeff-cuscutis have provided the ways to configure expiration of the HTTP Response Headers using XML configuration in the web.config file of a ASP.NET application
How to configure static content cache per folder and extension in IIS7?
ou can set specific cache-headers for a whole folder in either your root web.config:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<!-- Note the use of the 'location' tag to specify which
folder this applies to-->
<location path="images">
<system.webServer>
<staticContent>
<clientCache cacheControlMode="UseMaxAge" cacheControlMaxAge="00:00:15" />
</staticContent>
</system.webServer>
</location>
</configuration>
Or you can specify these in a web.config file in the content folder:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<staticContent>
<clientCache cacheControlMode="UseMaxAge" cacheControlMaxAge="00:00:15" />
</staticContent>
</system.webServer>
</configuration>
I'm not aware of a built in mechanism to target specific file types.
You can do it on a per file basis. Use the path attribute to include the filename
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<location path="YourFileNameHere.xml">
<system.webServer>
<staticContent>
<clientCache cacheControlMode="DisableCache" />
</staticContent>
</system.webServer>
</location>
</configuration>
My IIS7 web.config is set to the following with a folder of static assets (not within an ASP.NET app or anything):
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<staticContent>
<clientCache cacheControlCustom="public" cacheControlMode="UseMaxAge" cacheControlMaxAge="500.00:00:00" />
</staticContent>
<httpProtocol allowKeepAlive="false" />
</system.webServer>
</configuration>
When I try to access a Silverlight .XAP file, I expect IIS to tell the browser that it can be cached for 500 days.
However, this is the cache header:
Cache-Control: no-cache,public,max-age=43200000
Why is IIS still adding no-cache to this header with the above configuration file?
You need to configure IIS to treat XAP as static content. Try this:
<configuration>
<system.webServer>
<staticContent>
<mimeMap fileExtension=".xaml" mimeType="application/xaml+xml" />
<mimeMap fileExtension=".xap" mimeType="application/x-silverlight-app" />
<mimeMap fileExtension=".xbap" mimeType="application/x-ms-xbap" />
</staticContent>
</system.webServer>
</configuration>