Make static resource available in Azure Web Role - c#

I need to access a web api in an Azure Web Role from a legacy Flash Application, and in order to do this Flash needs to be able to access a file called crossdomain.xml. I have added this file to the root of the application, but if I go to https://myapp.com/crossdomain.xml in the browser the file is downloaded. How can I get the xml to be shown in the browser?

Static xml files can be served by adding the following to web.config:
<handlers>
<add name="XMLHandler" type="System.Web.StaticFileHandler" path="*.xml" verb="GET" />
</handlers>
<staticContent>
<mimeMap fileExtension=".xml" mimeType="application/xml" />
</staticContent>

Related

How does IIS Know how to start .NET Web Application

I'm trying to understand how IIS knows how to start my ASP.Net Web Application My understanding so far is that, when creating a web application we create a Web.Config which defines how IIS will start it's process
So We have a Web Config
<system.webServer>
<modules runAllManagedModulesForAllRequests="true">
<add name="LogRequests" type="BDBPayroll.Apps.API.Web.Shared.HttpModules.LogRequestsHttpModule, BDBPayroll.Apps.API.Web.Shared" />
<add name="MiniProfiler" type="BDBPayroll.Apps.API.Web.Shared.HttpModules.MiniProfilerHttpModule, BDBPayroll.Apps.API.Web.Shared" />
</modules>
<handlers>
<remove name="ExtensionlessUrlHandler-Integrated-4.0" />
<remove name="OPTIONSVerbHandler" />
<remove name="TRACEVerbHandler" />
<add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="*" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
</handlers>
</system.webServer>
And The Global Asax:
public class WebApiApplication : WebApiHttpApplication<WebModule>
{
protected override void Configure(HttpConfiguration config)
{
config.Filters.Add(new Filters.ContextResolverFilter());
config.Filters.Add(new ValidateModelAttribute());
config.Filters.Add(new PaginationFilter());
GlobalContext<JsonFormatterRule>.Instance.SetDefaultJsonFormatter(config);
}
//...
}
Since IIS can run multiple applications e.g php, .net etc, How does IIS Know from the Web Config To run the Global Asax.
My guess is that it looks up the application type from the web config, and then searches for WebApiHttpApplication, Does anybody have any more information on this process?
Since IIS can run multiple applications e.g php, .net etc, How does IIS Know from the Web Config To run the Global Asax.
My guess is that it looks up the application type from the web config, and then searches for WebApiHttpApplication, Does anybody have any more information on this process?
As far as I know, if use send the request to the IIS.
After handling the http request by http.sys, IIS will move this request to the w3wp.exe to handle it.
Since IIS could only handle htm or html static page, IIS will use ISAPI to handle the page which IIS couldn't handle.
ISAPI is a kind of extention handler to handle different kinds of pages like php, aspx, cshtml or something else.
You could find it from IIS manager console handler mapping icon.
Image as below:
The IIS will send the request to right http hanlder according to its extension. The handler moudule(e.g asp.net isapi) will load the CLR and web application(include the globalasax) to handle the request.

Configuring web.config for two different sites of same application

I have two urls of my application,suppose url/site1 and url/site2.
On url/site1 we have implemented Ad authentication and url/site2 has application login for external users. Now there some attributes in web.config due which i'm having separate deployment folder each mapped to /site1 and /site2 under default website. I want to maintain only one set of deplyment folder . Is there a way i can configure different scenarios for each of this websites under same web.config.Mainly these 4 lines given below will have different values for each site, how can i accommodate it in same web.config so that i can keep only one deployment folder mapped to each of these sites in IIS manager.
<add key="owin:AutomaticAppStartup" value="true"/>
<add key="VirtualDirectory" value="/XYZ"/>
<add key="SiteName" value="XYZ"/>
<defaultDocument>
<files>
<clear />
<add value="UserLogin.aspx" />
</files>
</defaultDocument>

Make IIS 7.5 pass *.xml requests to asp.net

How do I configure IIS 7.5 to forward all *.xml file requests to asp.net engines so i can handle them in Global.asax and rewrite the path to a *.aspx file? Now IIS is expecting to find them directly on disk. I will use this do dynamically generate my sitemap.xml
You can force static files to go through the ASP.NET pipeline by editing your web.config:
<system.webServer>
<handlers>
<add name="XMLHandler" type="System.Web.StaticFileHandler" path="*.xml" verb="GET" />
</handlers>
</system.webServer>
HTTP Handlers and HTTP Modules Overview
How to: Register HTTP Handlers

Custom server control and Generic Web handler

I'm creating a custom server control which uploads files asynchronously to the server.
This solution uses flash element that posts the files to Generic Web handler aka ashx which then saves the posted file in a desired location.
It works grate, but with this approach I do need to create ashx file in each project, potentially, to handle the posts from the flash element.
What I would like to achieve is fully encapsulated server control that will use it's own ashx (or whatever can replace it) handler to upload the files.
Is it possible to do? Any ideas would be welcome.
Thanks.
You could include the handler within the class library containing the control and then only register it in web.config using the <httpHandlers> section:
<configuration>
<system.web>
<httpHandlers>
<add verb="*"
path="upload.ashx"
type="MyControl.MyUploadHandler.New, MyControl" />
</httpHandlers>
<system.web>
</configuration>
and if you are using IIS 7 Integrated pipeline mode to the <handlers> section:
<system.webServer>
<handlers>
<add name="UploadHandler"
verb="*"
path="upload.ashx"
type="MyControl.MyUploadHandler.New, MyControl" />
</handlers>
</system.webServer>
And if you are using ASP.NET 4.0 you could checkout the PreApplicationStartMethod infrastructure which allows you to dynamically register handlers:
[assembly: WebActivator.PreApplicationStartMethod(typeof(MyControl.StartUp), "PreApplicationStart")]

Windows Azure - Serve unknown (mp4) MIME types in Windows Azure IIS storage

I have a windows azure deployment (a web-role) that on request pulls in a pair of video files (mov and mp4) from azure storage into it's own local IIS storage, which I then access through the browser.
It may sound silly, but I have good reasons for doing this.
Unfortunately, I am unable to access the mp4 files. The mov are fine, but the mp4 give me "404 - File or directory not found."
I've looked into this, and it seems to be because IIS will not return unknown file types, and mp4 must fall under this category. If it was a normal IIS server I would be able to register the mp4 mime type, but I don't know how to go about this in Windows Azure.
I could RDP in and do it manually, but this would not be practical as the role is replaced frequently and would mean I would need to re-do it manually every time. It must be done through one of the config files or in code.
Can anyone help?
Thanks!!
Steven
Can you not add custom mime type in web.config? I just ran into this link:
http://www.iis.net/ConfigReference/system.webServer/staticContent/mimeMap
The relevant web.config xml is:
<configuration>
<system.webServer>
<staticContent>
<mimeMap fileExtension=".syx" mimeType="application/octet-stream" />
<mimeMap fileExtension=".tab" mimeType="text/plain" />
</staticContent>
</system.webServer>
</configuration>
Hope this helps.
I used suggestion from https://social.msdn.microsoft.com/Forums/azure/en-US/79eb0c22-fe78-41d6-ac57-03055610b2a8/mp4-media-files-on-azure-website?forum=windowsazurewebsitespreview&prof=required:
<staticContent>
<remove fileExtension=".mp4"/>
<mimeMap fileExtension=".mp4" mimeType="video/mp4" />
<clientCache cacheControlMode="UseMaxAge" cacheControlMaxAge="7.00:00:00" />
</staticContent>
To configure the mime type, create a new web.config file with this content in the video folder:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<staticContent>
<mimeMap fileExtension=".mp4" mimeType="video/mp4" />
<clientCache cacheControlMode="UseMaxAge" cacheControlMaxAge="7.00:00:00" />
     </staticContent>
</system.webServer>
</configuration>
This solution works for Azure only, the local project may no longer work. My solutions is to use "Add Config Transform" for the plublication with an empty web.config file for local project:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
</configuration>
And when you right click on web.config, select "Add Config Transform":
In the web.Release.config file add this into de configuration tag:
<system.webServer xdt:Transform="Insert">
<staticContent>
<mimeMap fileExtension=".mp4" mimeType="video/mp4" />
<clientCache cacheControlMode="UseMaxAge" cacheControlMaxAge="7.00:00:00" />
</staticContent>
</system.webServer>
For the answer to the specific question about playing videos in MIME Type of MP4.
answered here

Categories