Trying to Programmatically Expire the HTTP Response Headers - silverlight

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>

Related

Hosting backend files onto IIS

I'm trying to upload my website onto the web. I have two folders for holding my front-end React files and another for the back-end files that uses Nodejs, cors, and express. It also has my API and middleware.
The front-end pages have already been uploaded onto my IIS and port forwarded with my router, so I can access that anywhere with my IP. But it doesn't function well without my backend files, how can I host the backend files as well and make them work together?
I am getting a headache doing this, does anyone know how to do this??
Thanks in advance.
As far as I know, if you want to host node.js application, you should firstly install the node.exe and the a build of iisnode.
node.exe
iisnode
After installed the IIS nodes, you could set up samples, from the administrative command prompt call %programfiles%\iisnode\setupsamples.bat.
Then you could go to http://localhost/node to see the example.
The next step is to deploy the node.js application inside one iis web application.
Lastly, you should create or modify the web.config to use the iisnode modules.
For example,
<configuration>
<system.webServer>
<handlers>
<add name="iisnode" path="app.js" verb="*" modules="iisnode" />
</handlers>
<rewrite>
<rules>
<rule name="mysite">
<match url="/*" />
<action type="Rewrite" url="app.js" />
</rule>
</rules>
</rewrite>
<defaultDocument>
<files>
<add value="app.js" />
</files>
</defaultDocument>
</system.webServer>
More details, you could refer to below article:
https://www.hanselman.com/blog/InstallingAndRunningNodejsApplicationsWithinIISOnWindowsAreYouMad.aspx

After webapp was deployed to azurewebsites.net, cannot load xml file from subfolder

I have an AngularJS app.
I have the following folder structure:
ROOT
-app
-data
index.html
In my service I load bookmarks.xml file, located in data folder:
this.$http.get('data/bookmarks.json').then(...)
When I run site locally: http://localhost:8080 everything works fine, the file is loaded and rendered.
After I deployed my app to Microsoft Azure, azurewebsites.net, I get this error message where my code loads the bookmarks.json file:
Possibly unhandled rejection: {"data":"The resource you are looking for has been removed, had its name changed, or is temporarily unavailable.","status":404,"config":{"method":"GET","transformRequest":[null],"transformResponse":[null],"jsonpCallbackParam":"callback","url":"data/bookmarks.json","headers":{"Accept":"application/json, text/plain, /"}},"statusText":"Not Found"}
Any idea why this is happening? Looks like it cannot locate the file in data folder. The file is there of course. Tried "/data/bookmarks.json" - no effect.
In your web.config, check the section. This section determines what MIME types your web application is allowed to serve. Make sure that you have the following if you want to be able to download .json files:
<staticContent>
<mimeMap fileExtension=".json" mimeType="application/json" />
</staticContent>
If you don't already have a web.config file (for example, if you're just serving static content), add this as your web.config:
<?xml version="1.0"?>
<configuration>
<system.webServer>
<staticContent>
<mimeMap fileExtension=".json" mimeType="application/json" />
</staticContent>
</system.webServer>
</configuration>

HTTP 404: The /Media directory is not serving images

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" />

IIS7: Cache Setting Not Working... why?

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>

Adding Silverlight MimeType using adsutil

I have a script that creates an app pool, web site - and then I want to use adsutil to add the .xap MimeType.
I see this:
cscript adsutil.vbs set W3SVC//Root/MimeMap “.extension,mimetype”
However, since I am creating the web site in the same script I will not know the ID.
Would anyone know how to do this with adsutil?
Thanks,
Rich
You could always add the MimeType using web.config instead:
<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>

Resources