I'm trying to serve some static content (Jekyll if that's relevant) out of an Azure web app. Said web app can also be served out of an Azure CDN. Both urls (CDN and app) work fine.
A chrome audit complains that the assets of my page are missing cache expiration dates. Fair enough.
But uhhh...how do I set cache expiration for an Azure web app or an Azure CDN endpoint?
Can they be set somewhere in the HTML? Can they be set somewhere in the wilds of the Azure console?
Most google answers (including SO) explain how to set the expiration via a web.config file, but I don't have one of those, because my application is not a .NET app.
The answer to my question turns out to be dead simple. I just needed to add a web.config file to the root of my jekyll app. Like so:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<staticContent>
<clientCache cacheControlMaxAge="365.00:00:00" cacheControlMode="UseMaxAge"/>
</staticContent>
</system.webServer>
</configuration>
Coming from a Linux background, I assumed the web.config was a .NET thing, but nope. It sets the IIS (that is, Azure) configuration.
Related
I Have an Angular application which is hosted in azure web app. I want to access video file by requesting url like https://something.azurewebsites.net/htmldelivery/assets/videos/test.mp4 But I was not able to served requested video file from web app. It simply return "The resource you are looking for has been removed, had its name changed, or is temporarily unavailable."
App Service Plan :S1 & Location : UK West
This is how it look like my current directory structure in the web app.
When I request the video file directly from browser https://something.azurewebsites.net/htmldelivery/assets/videos/test.mp4 it returns me 404 file not found error.
Does anyone have any idea about this issue ? I was trying to configure Virtual applications and directories in web app configuration but still did not worked for me. I was changing the physical path up to site\wwwroot\htmldelivery\assets\videos\test.mp4 but still no success.
After further investigation I came to the point that Azure web apps need some configuration to configure the mimeType in your web.config to work with video files in Azure Web App. So I have just simply created a web.config file into the root directory and it works well.
<configuration>
<system.webServer>
<staticContent>
<mimeMap fileExtension=".mp4" mimeType="video/mp4"/>
<mimeMap fileExtension=".ogv" mimeType="video/ogg"/>
<mimeMap fileExtension=".webm" mimeType="video/webm"/>
</staticContent>
</system.webServer>
I am deploying ASP.NET Core Web API for the first time.
I am facing issues and confused on few things.
1) I followed this link Host ASP.NET Core Web API and have no issues until step 5. My Core Web API has Swagger UI and UI not showing up.
2) I followed this link Deploy ASP.NET Core to IIS and in step 3 I am not sure how he gets Add Application. My IIS always show Add website.
I followed this link too Host ASP.NET Core on Windows. I tried from 2 days haven't get working on IIS.
I deployed using Web Deploy and Folder too. None of them worked
This is my Web Config file
After Diagnostics, I am here. Runtime doesnot match. I tried to install from that link and still not working.
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<location path="." inheritInChildApplications="false">
<system.webServer>
<handlers>
<add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModuleV2" resourceType="Unspecified" />
</handlers>
<aspNetCore processPath="dotnet" arguments=".\SampleCoreApi.dll" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" />
</system.webServer>
</location>
</configuration>
The first link is talking about hosting the ASP.NET Web API and not ASP.NET Core Web API.
When you are hosting ASP.NET Core app/api, you need to set the .NET CLR version of the application pool to No Managed Code
This is also mentioned in the Step 3 of the second link. It's creating an application under the Default Web Site, that's where you see the Add Application option. It's not necessary to create an application under the Default Web Site.
You can either create the Application Pool first and set it to No Managed Code. Then, when adding a new website, you can select this application pool
Or, add a new website first. That will create an application pool automatically with the same name as the web site. Then, you edit the application pool and set it to No Managed Code
I hope that helps.
We are hosting an ASP.NET Core application on an Azure App Service (Web Apps).
Our individual instances take some time to "preload" the required data needed to process requests. But when scaling out, requests will be routed to the instances still being prepared.
How does the App Service load balancer decide when an instance is ready and requests can be routed to it? Is there a way to prevent routing to some specific instance until we deem it ready?
Try using the applicationInitialization node in your web.config. This instructs IIS to to issue warm-up requests to URLs that you designate before the application receives its first request.
I have used this on slow swaps before. But from reading the docs on IIS here, it looks like it'll also work for new instances. I haven't tried this when scaling out though - let me know if this works for you.
Here's example code of using it within the web.config:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.webServer>
<applicationInitialization>
<add initializationPage="/pagetowarmup1.php" />
<add initializationPage="/pagetowarmup2.php" />
<add initializationPage="/pagetowarmup3.php" />
</applicationInitialization>
</system.webServer>
</configuration>
I have created a web site using the standard ASP.Net MVC 5 template with no authentication. I have added MVCSiteMapProvider from NuGet. On my dev machine the /sitemap.xml endpoint returns the correct sitemap once I add the UrlRoutingModule-4.0 to web.config. If I publish to Azure Web Sites the /sitemap.xml endpoint also works. However if I publish to my local hoster the /sitemap.xml endpoint returns a 404 - File or directory not found.
Any idea what I need to change / add to web.config to get the endpoint working?
Thanks
Tim
As far as I am aware, this configuration is all that is required to make it function in MVC4/MVC5:
<system.webServer>
<modules>
<remove name="UrlRoutingModule-4.0" />
<add name="UrlRoutingModule-4.0" type="System.Web.Routing.UrlRoutingModule" />
</modules>
</system.webServer>
But then, I don't have much of an idea why this line is required, a contributor figured it out and I added the solution to the NuGet package.
Right now I have a traditional static HTML site (generated by Jekyll, FWIW) with assets being served by an old-school Apache server.
I am keen to migrate this to an Azure static site stored in blob form and delivered via the CDN for improved performance.
The trouble is that I have an .htaccess file that handles several 301 redirects for me to maintain links to old popular pages that have moved. I'm not sure how to replicate this functionality on Azure short of running my own full LAMP stack with an Apache server in a VM just to perform this rudimentary function.
Is my only option to pay the $10 or so per month needed to setup an IIS instance to do the redirects for me (via IIS's mod_rewrite importer)? I believe this is what Azure refers to as simply their "shared website" product.
I would prefer a cheap and simple solution that doesn't require the cost and technical overkill of a full VM and just bills me for the bandwidth. Is there some Azure URL redirect feature somewhere that I'm missing? Any other clever solution anyone can think of?
In Azure Websites, you can do 301 redirects using a web.config file,
See Using web.config file for redirect for sample web.config:
<configuration>
<location path="oldPage1.htm">
<system.webServer>
<httpRedirect enabled="true" destination="http://www.newDomain.com/newPage1.htm" httpResponseStatus="Permanent" />
</system.webServer>
</location>
<location path="oldPage2.htm">
<system.webServer>
<httpRedirect enabled="true" destination="http://www.newDomain.com/newPage2.htm" httpResponseStatus="Permanent" />
</system.webServer>
</location>
<!-- etc. -->
</configuration>