File published to successfully to Azure web site can't be found? - azure

I have an Azure shared web site. I publish my web site using Visual Studio 2013 and the operation succeeds, yet certain files are reported by the browser as missing while others are fine. The files that end up in the missing category are all binary data files for a game. All the "normal" web files (HTML, JS, CSS, etc.) appear to be fine. Is there some kind of special steps I need to take to publish binary data to an Azure web site?
Note, from within Visual Studio 2013 I tried to publish individually one of the missing files by using the Publish Single File option. The publish operation succeeds, but still, the browser can't find the file when it tries to load it. Note, I don't think it's a file size issue because several of the binary data files are only around 3 MB in size.

To fix this issue, FTP into your website and upload the following Web.config file which will set the correct MIME types. If you already have a Web.config file in place, just add the below to the appropriate section. Replacing .json and application/json with the file you're trying to load.
<?xml version="1.0"?>
<configuration>
<system.webServer>
<staticContent>
<mimeMap fileExtension=".json" mimeType="application/json" />
</staticContent>
</system.webServer>
</configuration>

I'm guessing in this instance you haven't configured the mimeTypes for these files, if they are to be served through the server. There's a quick explanation and an appropriate resolution to your problem.
HTH

Related

IIS: How to serve a file without extension?

I am using IIS 8 on Windows 8.1. I have an XML file an I need to have it accessed through (servername)/(path)
(path) is predefined by someone else and does not contain an extension. I tried the simple solution of removing the .xml file the file name, but IIS returns HTTP Error 404.3 - Not Found
In the "Physical Path" returned with the error is the correct file path, which when I copy-paste to Run opens the correct file.
Please let me know if this is possible.
Assuming (path) is a physical directory on your machine, create a new web.config file in that directory with the following content:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<staticContent>
<mimeMap fileExtension="." mimeType="text/xml" />
</staticContent>
</system.webServer>
</configuration>
You are telling IIS that for this directory only, any file without an otherwise defined extension (in MIME types) should be considered an xml file. Other file types in the same path should still work.
If you have the Windows feature IIS Management Scripts and Tools installed, you can use PowerShell to create such a web.config file:
Add-WebConfigurationProperty -pspath 'MACHINE/WEBROOT/APPHOST/Default Web Site/.well-known' -filter "system.webServer/staticContent" -name "." -value #{fileExtension='.';mimeType='text/xml'}
in this example Default Web Site is the name of the web site and .well-known is a directory under that site.
It can be done in IIS 6 as well / without using web.config, but instead using the management GUI to add a MIME type for extension . here:
For instance, to serve a .well-known/acme-challenge token, create a virtual directory called .well-known, and have it take its contents from a physical directory (that cannot have names with leading dots in windows). Then add a text/plain MIME type for the extension . in this directory, and you can manually acquire new letsencrypt certificates for a domain that is currently served by an old IIS.
Changing the configurations by hand can be error-prone. So Internet Information Server (IIS) console GUI provides an easier and error-free way to update the MIME-types. Please follow the steps below:
Open IIS
Expand your website's node in the left navigation pane.
Select your application or virtual directory.
Double-click MIME Types feature under IIS section in the right pane:
Click Add.. link in Actions pane. Set-up the mime type to support all files without extension. Then click OK :
Behind the scene, these steps make changes to web.config file of your application or virtual directory (under your website) as suggested in PeterHahndorf's post.
Note: The screenshots shown in the steps above have been taken from Windows 10 machine having IIS v10.
for me, I want only to serve one file
so what I did is just add a simple rewrite as the other methods posted here didn't work for some reasons
<system.webServer>
<rewrite>
<rules>
<rule name="apple-app-site-association" patternSyntax="ExactMatch">
<match url="apple-app-site-association" />
<action type="Rewrite" url="/apple-app-site-association.txt" />
</rule>
</rules>
</rewrite>
</system.webServer>

Include TypeScript files in azure git deploy

I'm trying to include TypeScript files in my automatic git deploy so I can showcase code for a framework I'm building. However, whenever I deploy to azurewebsites the deployments do not include the TypeScript files.
Site in question: http://endgate-samples.azurewebsites.net/Samples/AnimatedSprites/
What I've tried:
Copy all TypeScript files to output folder by setting TypeScript properties to "Copy Always". Issue with this is that I need to change the references to all the files (do not want to do this).
MSBuild pipeline. This works for file system deploy but not web deploy... https://github.com/NTaylorMullen/EndGate/blob/master/EndGate/samples/EndGate.Core.JS.Samples/EndGate.Core.JS.Samples.csproj#L896-L909.
Manual publish to FTP endpoint (works like a charm), but not automatic. Also requires the msbuild pipeline (#2)
What am I doing wrong or what can I do (that I haven't tried) to get my TypeScript files deploying automagically?
So after a lot of work it turns out that with the msbuild pipeline piece (#2) it will actually deploy the typescript files. One thing that I was missing was adding the appropriate mime type to handle typescript files.
It turns out by default IIS won't serve the TypeScript files correctly.
To add the Custom mime type I did:
<system.webServer>
<staticContent>
<remove fileExtension=".ts"/>
<mimeMap fileExtension=".ts" mimeType="text/plain" />
</staticContent>
</system.webServer>
It's important that we remove the existing .ts mime type (if there is one) prior to adding the mime type. If you deploy onto a machine that has the .ts mime type already and you do not remove prior to adding, it will pretty much destroy your existing mappings and will fail to serve any css, js files etc.
This has been a battle but I finally got it working, hope this helps somebody else in the future!

AjaxMin not working on Azure site

I am using Microsoft's AjaxMin to minify javascript on my website, which is hosted by Azure. I am using a BuildTask to automatically minify javascript at run time. This build task is specified in the .csproj file.
The process is working on my local environment, however, it does not work when I deploy to my Azure site. The azure site throws 404: file not found errors, when i try to reference the minified version of .js files.
Is it possible to use build tasks on an Azure site? Is there anything I am missing? I have made sure not to include the .min.js files in source control as this (http://www.asp.net/ajaxlibrary/AjaxMinQuickStart.ashx) tutorial suggests, but I am wondering if there is anything specific to Azure that I need to set up.
Thanks!
I've got this working properly in my projects. I'll tell you how I did it, though this may not be the simplest or most straightforward way.
Before we get started, it's helpful to be able to check if your minified files are included in the Azure deployment package without actually deploying. It's pretty easy to do. The .cspkg file is actually a zip-formatted file, so you can open it with any zip archiver. (I like to use 7Zip for this because the right-click -> Open Archive command doesn't require you to rename the file, but you could use Windows Explorer, WinRAR, etc.) Inside the .cspkg you'll see another large file with a .cssx extension. That's a zip file too. Inside of the .cssx you'll find a sitesroot folder with a subdirectory for each website you're deploying, which will contain all your actual website files. So you can poke around in there and see what files are being deployed to Azure.
First, try editing the project file for your web project (the one that contains all the Javascript/CSS files). You can use Notepad, or in Visual Studio right-click the project, select "Unload Project", then right-click again and select "Edit ". Inside the project file, insert a section like this:
<ItemGroup>
<!-- Copy over all the minified CSS & JS to the output directory-->
<Content Include="**\*.min.css" />
<Content Include="**\*.min.js" />
</ItemGroup>
Then reload the project, repackage it, and see if your files are included in the .cspkg file. If they are, then you're done.
If not, there are a couple other things to check. Your minification might not be running at the right build stage. My minification target looks like this:
<Target Name="PrepWebApp" Condition="$(Configuration)=='Release'" AfterTargets="AfterBuild">
If that's still not working and your Web Role has multiple Sites and/or Virtual Applications in it, it's possible that the packaging steps are not running for all of the sites. So when you go to package your project for deployment to Azure, it may still not be running the minification step (along with the web.config transformations, and some other things). If that's the case, see this blog post for a way to fix it.
Just in case that blog post goes away, I'll copy the most relevant bit here. You would put this in the .ccproj file for your web role (with appropriate bits changed to match your project structure):
<PropertyGroup>
<!-- Inject the publication of "secondary" sites into the Windows Azure build/project packaging process. -->
<CoreBuildDependsOn>
CleanSecondarySites;
PublishSecondarySites;
$(CoreBuildDependsOn)
</CoreBuildDependsOn>
<!-- This is the directory within the web application project directory to which the project will be "published" for later packaging by the Azure project. -->
<SecondarySitePublishDir>azure.publish\</SecondarySitePublishDir>
</PropertyGroup>
<!-- These SecondarySite items represent the collection of sites (other than the web application associated with the role) that need special packaging. -->
<ItemGroup>
<SecondarySite Include="..\WebApplication1\WebApplication1.csproj" />
<SecondarySite Include="..\WebApplication2\WebApplication2.csproj" />
</ItemGroup>
<Target Name="CleanSecondarySites">
<RemoveDir Directories="%(SecondarySite.RootDir)%(Directory)$(SecondarySitePublishDir)" />
</Target>
<Target Name="PublishSecondarySites" Condition="'$(PackageForComputeEmulator)' == 'true'
Or '$(IsExecutingPublishTarget)' == 'true' ">
<!--
Execute the Build (and more importantly the _WPPCopyWebApplication) target to "publish" each secondary web application project.
Note the setting of the WebProjectOutputDir property; this is where the project will be published to be later picked up by CSPack.
-->
<MSBuild Projects="%(SecondarySite.Identity)" Targets="Build;_WPPCopyWebApplication" Properties="Configuration=$(Configuration);Platform=$(Platform);WebProjectOutputDir=$(SecondarySitePublishDir)" />
The build task will run in Visual Studio when you build the project. You need to make sure that the minified files are also being deployed to Azure.
I'm guessing that perhaps because the item is being generated at build-time that it's not part of the project itself, and is this ignored by the deployment step.
Please check that the deployment system being used will include all the script files and not just the ones that are in the project itself.

configure common.logging in Azure

I'm developing an app. using Common.Logging (http://netcommon.sourceforge.net/index.html).
A simplified logging configuration (which is done in web.config) is as follows:
<configuration>
...
<arg key="configType" value="FILE" />
<arg key="configFile" value="NLog.config" />
...
</configuration>
As you can see here, the configuration points another configuration file (here, NLog.config) of a backend logging framework.
My question is: when deploying in Azure, what path should I specify here (on dev, NLog.config is copied when building the solution, and placed in the bin directory). In other words, what would be the SAFEST way to get the physical place where the app is deployed in Azure?
Thanks in advance!
In code you can find the current path to the application using Server.MapPath("/"). Now, you can simply make sure that the NLog.config file gets deployed to the application folder:
Add NLog.config to your project (in the root of your web application)
Change the Build Action to Content
In order to test this you can right click on your Azure project an choose Package. In the bin\Release|Debug\app.publish folder of your Azure project you'll find a *.cspkg file. Add a .zip extension to this file and open the file with WinRAR/ZIP/7zip/... Then you'll see a file like this one: SomeWebRole_1a91f39a-49b7-4ece-873f-862172a2fa06.cssx. Here again, add the .zip extension to this file and open it.
If you navigate to the sitesroot\0 folder you'll see the files of the web application in IIS, including the NLog.config file. This way, you' can simply reference the NLog.config file in the Common.Logging settings:

Sharepoint 2010 masterpage

I am creating a custom master page through feature in sharepoint 2010 visual studio and on deploying the feature I am getting this
Error occurred in deployment step 'Activate Features': Failed to instantiate file "custom.master" from module "CustomMaster": Source path "Features\WSPBuilderImportProject2_SiteElements2db64791-54f6-4571-a161-66e0ef6497f5\custom.master" not found.
RHM, your final url is doubled up. effectively you're trying to publish to _catalogs/masterpage/_catalogs/masterpage. try to only specify the list url in the module element and then put the remainder in without the path. I.e.
If you deploy the masterpage as part as an feature (SharePoint solution) with for example Visual Studio 2010, the MasterPage will be deployed to the features directory. The feature file will provision the masterpage to the MasterPage Gallery (_Catalogs). As long as the file is not customized by SharePoint Designer, sharepoint will serve the masterpage (by using the virtual path provider) from the filesystem and not from the database.
<File Path="MasterPageModule\abc.master" Url="_catalogs/masterpage/abc.master" Type="GhostableInLibrary" />
Deploy the master page. You can now control the master page by changing it from its physical location (SharePoint Root - 14 folder) and still be able to access from /_catalogs/masterpage/abc.master
The above is the recommended approach when you deploy master pages and page layouts.
This is a fairly self explained error. SharePoint is not able to find the file in the location you have specified in Elements.xml. Check the location if it exists and retry.
My module folder has master page in it with name of "custom.master" and here is the xml
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
<Module Url="_catalogs/masterpage" RootWebOnly="FALSE" Name="CustomMaster">
<File Type="GhostableInLibrary" Url="_catalogs/masterpage/custom.master" Path="CustomMaster\custom.master" />
</Module>
</Elements>
I was having this same problem and having checked and double checked all my paths, urls etc were correct the master was just not being provisioned by the feature.
It turned out the VS2010 had got a little confused and messed up the path in the spdata file. If you're in the same situation definitely worth checking.

Resources