How do I access uploaded files on Microsoft Azure websites? - asp.net

I wanted to upload some audio files to my azure [ASP.NET] website. I then came up with this idea: I created a WebAPI action responsible for uploading the audio files into an UploadedAudio folder that I created inside the Content folder (wich is a public folder, right?). Everything is working just fine in Debug mode.
After publishing to Azure, I can see that the files are persisted with paths like D:\home\site\wwwroot\Content\UploadedAudio\5ab46baa-ffa7-4b7f-bbb9-9d0c53fa0751.mp3, but I'm not able to play them like I can in Debug mode, because I get a NotFound error. Here is the URL that I use https://mywebsite.azurewebsites.net/Content/UploadedAudio/5ab46baa-ffa7-4b7f-bbb9-9d0c53fa0751.mp3. In Debug mode, http://locahost:port/Content/UploadedAudio/5ab46baa-ffa7-4b7f-bbb9-9d0c53fa0751.mp3 is working fine!
How can I access the uploaded audio files?
I hope that my problem is clear enough. If someone can help me with this...
Thanks.

Got it !! adding these lines to the web.config is the solution:
<system.webServer>
<staticContent>
<mimeMap fileExtension=".mp3" mimeType="application/octet-stream" />
</staticContent>

Related

Can't serve up files with custom file extension in ASP.NET despite mimetype declaration?

I'm working on an ASP.NET/MVC/Razor web site. I need to server up files with a "pdb" extension. The *.pdb files are plain ASCII text files. I tried adding the following declaration to my web.config file:
<system.webServer>
<staticContent>
<mimeMap fileExtension=".pdb" mimeType="text/plain" />
</staticContent>
</system.webServer>
But I still get a 404 error whenever I try to load one of the files:
HTTP Error 404.3 - Not Found
The page you are requesting cannot be served because of the extension configuration. If the page is a script, add a handler. If the file should be downloaded, add a MIME map.
I found this SO post that talks about running a utility to register the version of .NET you are using, but I believe the context is that of installing a web site on to other serves, not just a simple publish scenario like mine:
"The page you are requesting cannot be served because of the extension configuration." error message
What am I doing wrong? Note this is happening when I run locally with IIS Express from Visual Studio 2013 Update 4.

Prevent overwriting of a file when deploying?

NOTE: This is for a Visual Studio Web Site Project and NOT a Web Application
I am using web deploy to push changes from my development machine to my staging server. I would like to push any files that are different to the staging server except for one particular file (lets call it myFile.whatever)
So far I have tried editing the C:\Program Files\IIS\Microsoft Web Deploy V3\msdeploy.exe.config file to look like so:
<configuration>
<startup>
<supportedRuntime version="v2.0.50727" />
<supportedRuntime version="v4.0" />
</startup>
<rules> <------------ ADDED THIS NODE
<rule name="skipConfig" type="Microsoft.Web.Deployment.DeploymentSkipRuleHandler"
objectName="filePath" skipAction="Delete"
absolutePath="C:\inetpub\wwwroot\MyProject\myFile.whatever"/>
</rules>
</configuration>
But it is still overwriting the file in question on my staging server. I started by editing the msdeploy.exe.config on my dev machine and when that didn't work I updated the msdeploy.exe.config on my staging server as well, but again, still not working.
Am I going about this wrong? Any suggestions on preventing this file from being overwritten?
Since transforms are painful with web site projects you might be able to use this method: http://blogs.msdn.com/b/webdev/archive/2010/04/22/web-deployment-excluding-files-and-folders-via-the-web-application-s-project-file.aspx
As stated in the comments, what you would normally do is to have a base Web.config file, then one specific for debug and one specific for release. The debug or release portion would add/override the base one with things that are particular to this scenario. This way you can just upload both and everything will work fine.
To understand more about web.config transformation, please refer to: http://msdn.microsoft.com/en-us/library/dd465326(v=vs.110).aspx

How to publish generic file using web publish in Visual Studio?

I am using Visual Web Developer 2010 Express (I am using VS for 10 years) and I publish a web site using web publish to Azure. I want to publish a generic file lets say a .dat file that users will download. How should I add it to project so that it is published and available to download by users. I tried adding to specific folder in project, setting build to content and always copy. I can see the folder created but when I type specific URL , i got generic file or folder not found error. If I put an xml file to same folder , I can see it with direct url.
Internet Information Service does not serve the files that it does not know about. Your .dat file is not supported by IIS by default so you have to add it manually.
Add following configuration to your web.config file.
<configuration>
<system.webServer>
<staticContent>
<mimeMap fileExtension=".dat" mimeType="application/octet-stream" />
</staticContent>
</system.webServer>
</configuration>

ASP.Net IgnoreRoutes Does not work

I have an svg file as my assets and in routeconfig, I have mentioned the below code
routes.IgnoreRoute("{*svg}", new { svg = #"(.*/)?.svg(/.*)?" });
This seem to be working fine with cassini (Visual Studio 2012 Buit-in Deployment Server) but when I deploy it to Azure I get a 404.
Is my IgnoreRoute statement right ? or any other solutions ? all other images, style sheets seems to work ok.
Thanks a lot in advance.
You never have to ignore routes for files that physically exist on disk, the routing module will not try to route those requests. You only need to ignore routes to other virtual resources.
Azure web sites do not have a mime type configured for .svg files, at least at the end of last year they didn't. You can configure a mime type for svg in the <system.webserver> section of your web.config file:
<staticContent>
<remove fileExtension=".svg"/>
<mimeMap fileExtension=".svg" mimeType="image/svg+xml"/>
</staticContent>
The remove is there to prevent errors on servers that already have an entry for .svg. It's an error to add a duplicate fileExtension, but not an error to remove a non-existent extension.
More here: Configuration Tips For ASP.NET MVC 4 on a Windows Azure Website
Looking at Phil's Blog I think what you need is something like:
routes.IgnoreRoute("{*allsvg}", new {allsvg=#".*\.svg(/.*)?"});
Hope that helps.
What order are you declaring the routes? It could be that above that one you have default or catch-all a route that actually already handles the request and so your IgnoreRoute never gets hit.

Uploading large files through Web API in asp.net

I am working on Web API to upload video file.
Following code is working good for small files. I have uploaded 7mb files.
how to do multi-part video upload using api
Next i am uploading 200 mb file but it is not working throwing exception 'Request was Canceled'
I am still working on find out the details. If any one has experience in doing this can help.
Your code is probably correct since it works for small files, but don't forget to update IIS7 or IIS8's config to allow POST sizes of more than 30MB (the default limit of IIS is set to 30MB).
You'll need to edit your web.config and add this:
(in this example, it allows up to 250MB)
<system.webServer>
<security>
<requestFiltering>
<requestLimits maxAllowedContentLength="262144000"/>
</requestFiltering>
</security>
</system.webServer>

Categories

Resources