Showing posts with label azure-web-app-service. Show all posts
Showing posts with label azure-web-app-service. Show all posts

Saturday, December 2, 2017

502 error when redirecting stream from another site

Leave a Comment

In my WEB Api 2 controller I want to request file from one site and return this file from my controller. Here is the code

public HttpResponseMessage GetLecture() {                 HttpWebRequest request = WebRequest.CreateHttp("http://openmedia.yale.edu/cgi-bin/open_yale/media_downloader.cgi?file=/courses/spring11/phil181/mp3/phil181_01_011111.mp3");     request.Referer = @"http://oyc.yale.edu/courses/";      var receivedResponse = request.GetResponse();      HttpResponseMessage response = new HttpResponseMessage(HttpStatusCode.OK);                         response.Content = new StreamContent(receivedResponse.GetResponseStream());     response.Content.Headers.ContentType = MediaTypeHeaderValue.Parse(receivedResponse.ContentType);     response.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment");     response.Content.Headers.ContentDisposition.FileName = "phil181_01_011111.mp3";     response.Content.Headers.ContentLength = receivedResponse.ContentLength;      return response; } 

Locally it works fine and I can download the file but when I deploy it to Azure I'm getting 502 Error. Web server received an invalid response while acting as a gateway or proxy server.

enter image description here

Logging shows that it fails after returning response so no exceptions during method execution.

It's ~50MB file. For smaller files code works fine.

How can I make this code works on Azure for 50 MB files?

2 Answers

Answers 1

First off, I will recommend configuring remote IIS administration for your Azure Web App since that will allow you direct access to IIS logs and associated settings. I have a strong feeling that the problem has to do with IIS/ASP.NET limits. You already pointed out that the method completes execution within seconds so this is likely not a timeout problem.

You also mentioned that the code works for smaller file sizes but fails when the size is increased. This points towards IIS bufferingLimit for your website being set to a small value (or perhaps the default value of ~4 MB). Here is a link describing how you can increase this limit to the desired value. Hope this works for you. If it doesn't, I would recommend digging into those IIS logs for your website.

Answers 2

The error message talks about the content, have you tried other content types rather than the one you get here receivedResponse.ContentType ?

You said in previous comments that the error appears with Google drive and above URL, so it mey depends on the returned content type.

Also, you are returning a stream not the file as a whole, while specifying ContentDisposition to be "attachment".

so maybe "audio/mpeg" will solve it or some other content-type that works will with streams.

Read More

Tuesday, May 3, 2016

Same Table, Notification Hub and server for two apps

Leave a Comment

We got caught by Microsofts abandonment of silverlight and focus on UWP. This has ended up with us having to develop two dually focussed apps (UWP and Silverlight), which has left us with two apps that cannot be bundled/packed together. We have therefore decided to have of the apps as a companion app.

Both apps use authentication, at present time it is with Microsoft authentication. The services used for authentication is of the type Azure App Service - Mobile. The services besides authentication also provides interfaces to a notification hub, blob storage and SQL storage.

The question is therefore is it possible to have one App Service - Mobile (not mobileservice), and authenticate two different apps using the same service? Additionally can the same Notification Hub be used to send notifications towards different apps?

Or is it needed that we create two different services for each application to facilitate the use of authentication and push messages. Then we can link the same database to the two App Service - Mobile ? But this would leave the issue of the notification hubs not having the same registrations ?

3 Answers

Answers 1

I dont think you can have more than one apps connected to one Azure mobile app. You can connect same app on different platforms but not multiple applications for same platform as Mobile app is designed to be an individual app back end. Check this feedback request. https://feedback.azure.com/forums/218849-notification-hubs/suggestions/3821272-push-notifications-for-multiple-apps

Answers 2

As answered by product group, the idea behind Mobile App is to be the individual backend. For that, Mobile Apps dashboard should have not one field for the PackageId/..., but two or more to be the backend for a different apps. Every connection between app and external service like a authentication provider or push notification platform is "personalized" - by IDs and password or certificates, or many ways.

I can imagine the scenario when someone would need to connect one backend to different apps, but the Azure Mobile App idea is different. And, as App Service is a service, i think that in the current situation what you want to do is impossible.

Answers 3

an Azure Mobile App consists of the client app and a backend in Azure. There's no stopping you reusing the same backend for more than one app.

Read More

Thursday, March 17, 2016

Unable to publish Django project to Azure Web App from VS2015

Leave a Comment

I've written a Django project in Visual Studio 2015 which runs successfully on a local server when debugging via the IDE. However, when I...

  1. Right-click the project in Solution Explorer and select Publish
  2. Select Microsoft Azure Web Apps as the publish target
  3. Click New... and enter details to create a new web app on Azure:
    • creating a new App Service Plan with the same name as the Web App
    • creating a new Resource Group with the same name as the Web App
    • Region: North Europe
    • Database server: No database
  4. Click Create
  5. Select Publish method: Web Deploy and successfully Validate Connection to new Azure Web App
  6. Click Publish

...the Output window shows that the Publish failed:

------ Publish started: Project: RaceLogger, Configuration: Debug Any CPU ------ Validating Web Deploy package/publish related properties... Gather all files from Project items @(Content). Adding: app\templates\app\performance_form.html;app\templates\auth\login.html;app\templates\index.html;app\templates\layout.html;app\templates\app\performance_detail.html;app\templates\app\performance_list.html;requirements.txt Gather all files from Project output (IntermediateSatelliteAssembliesWithTargetPath). Adding: Gather all files from Project items @(ReferenceCopyLocalPaths,ReferenceComWrappersToCopyLocal,ResolvedIsolatedComModules,_DeploymentLooseManifestFile,NativeReferenceFile). Gather all files from Project items @(AllExtraReferenceFiles). Adding: Gather all files from Project items @(_binDeployableAssemblies). Adding: DjangoStaticUrlSetting=/static/ Regenerating web.config Copying file from "C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v14.0\Python Tools\web_config.xml" to "obj\Debug\web.config". Updating app settings in web.config Made 1 replacement(s). Updating rewrite conditions in web.config Made 1 replacement(s). Updating FastCGI handlers in web.config Made 1 replacement(s). Copying file from "obj\Debug\web.config" to "C:\Users\username\Documents\Files\Web_Projects\django\RaceLoggerProject\RaceLogger\web.config". Regenerating web.debug.config Copying file from "C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v14.0\Python Tools\web_debug_config.xml" to "obj\Debug\web.debug.config". Updating ptvsd secret in web.debug.config Made 1 replacement(s). Copying file from "obj\Debug\web.debug.config" to "C:\Users\username\Documents\Files\Web_Projects\django\RaceLoggerProject\RaceLogger\web.debug.config".  ========== Build: 0 succeeded, 0 failed, 1 up-to-date, 0 skipped ========== ========== Publish: 0 succeeded, 1 failed, 0 skipped ========== 

I've checked that the newly created Azure Web App is running via the Azure Management Portal and have modified the Web App's Application settings so that Python version 3.4 is selected (in my local environment I'm running Python 3.4.4 and Django 1.9.3) to no avail. I've tried updating to VS2015 Update 2 RC, but this makes no difference either.

I've also tried creating the sample Django Web Project available in the New Project window of VS2015 in a Python 3.4.4 / Django 1.9.4 virtual environment and that fails to publish in exactly the same way.

Does anyone have any suggestions as to how to successfully publish a Django project to an Azure Web App from VS2015?

Any assistance would be much appreciated.

1 Answers

Answers 1

Have you tried to use virtual environment to specify your python version, which will not be limited by Python versions on Azure Web Apps Service.

Right click the Python Environments section under the solution, click the Add Virtual Environment.

enter image description here

Select the python version, mark Download and install packages, click Create button to create a new virtual enviroment under your solution directory. enter image description here

Press F5 to debug for testing the application, then try to deploy to Azure again.

Read More