Web API Dependency Resolver in Windows Azure Web Sites - azure

After publishing a project with WebAPI to Windows Azure Web Sites, I started getting exceptions tossed complaining that my API controllers didn't implement a default constructor.
I'm using Ninject in my project, and when I explicitly register the NinjectDependencyResolver in my GlobalConfiguration, the issue in Azure is resolved.
What I'm puzzled by is why I don't encounter this issue on my local development machine. Can anyone explain the configuration different in MAWS that causes this extra step to be necessary?

Related

Web API app with OWIN 'SystemWeb' on Azure App Service

I am creating app which uses Identity 2.1.0 framework in .NET. I started project in Visual Studio 2015 as Empty Web App (template). Now, I use Microsoft.AspNet.WebApi.Owin, and also Microsoft.Owin.Host.SystemWeb NuGet packages in my project. I understand that OWIN is a specification made to avoid monolithic frameworks and to specify how smaller application components interact with servers. However, I have requirement to deploy to Azure App Services.
I have found examples (blogs) where people deploy OWIN Web Api app as self-hosted to the Azure Cloud Services worker role. But I don't want this, as I don't use Cloud Service.
Since I am using Microsoft.Owin.Host.SystemWeb, am I going to be able to deploy this to Azure App service (which I assume manages internal IIS instance) ?
.NET ecosystem newbie here - so please excuse me for any possible redundancies in the question.
Microsoft.Owin.Host.SystemWeb is designed for hosting in IIS and all Azure App Service web apps are hosted in IIS, so this is exactly what you want (In fact, self-hosting likely won't work with Azure App Service).

IIS 7.5 + MVC 5 + NInject + PostSharp - Suddenly 401 on remote machine

I have a web application developed in VS2013
ASP.NET MVC 5
NInject for IoC
Sql Server 2008 R2 for a backing store (ADO, not Entity Framework, for DAL)
IIS 7.5 (Not a web garden, max processes = 1)
PostSharp 3.1.46.0
I have been developing and deploying on my local machine this application to a development server for months with not too many issues.
App Pool is .Net 4.0 Integrated, using the ApplicationPoolIdentity
Anonymous and Forms authentication are enabled. Anonymous is set to use the App Pool identity
File permissions are set for the application folder to give IIS AppPool\[mypool] read, list, execute access. (I tried full access, once, and it didn't help)
Last week, the development server reports a 401 (sc-status:401 sc-substatus:0 sc-win32-status:0) instead of showing me any forms from a remote connection. Local connections, that is, when I access the app on the sandbox, or if I log on to the development server and access it locally, work as expected. Any request from a remote machine fails.
401 - Unauthorized: Access is denied due to invalid credentials.
You do not have permission to view this directory or page using the credentials that you supplied.
I tried recreating the app pool and re-assigning the app to it. I tried aspnet_iisreg -ir. I went through most of the "Similar Questions" to the right of this edit box, trying to find something close to my issue. I erased the application from the server and redeployed to a new app, with new name and a new physical folder. KB2545850 hotfix didn't help.
My deployment strategy is an xcopy of everything but the web.config(s) I maintain the web.config separately. Please help diagnose.
In ASP.NET MVC Deploying an app with forms authentication to IIS 7.5 it says:
If you have a path leading to an eventual [Authorize] attribute, that will cause this -
removing the RenderAction or allowing that action to render without [Authorize] fixes it.
That was similar to my issue. I have a global filter to Authorize. I recently added a partial view in a controller to display a serial number. I added that partial to the _Layout, without the AllowAnonymous. Since the login form used the layout, which used this partial, I couldn't log in until I logged in.
Adding an [AllowAnonymous] to the action resolved this issue. I am thinking about how to more easily detect this for when it happens to me again.

Web API on Azure errors until App Pool is Recycled

I have a web role that hosts 4 MVC 4 sites. One of the sites (let's call it the API site from now on) uses both MVC and Web API. When I upgrade the web role, the Web API controllers from the API Site returns a 500 Internal Server Error to all requests. The MVC controllers work as expected and I know the request is getting at least as far as the Application_BeginRequest method of the global.asax. I'm not seeing anything logged in my Elmah log. The only hint I have of anything being wrong is the following in the event log:
The application '/' belonging to site '1' has an invalid AppPoolId 'DefaultAppPool' set. Therefore, the application will be ignored.
As web roles use App Pools with guids as identifiers I don't know where this is coming from.
What is most confusing is that once I recycle the app pool for the API site (which is a guid) everything starts working correctly.
I've tried recyling the app pools as part of a startup task on the role, but that doesn't seem to make any difference.
Any suggestions about what I can do to get Web API to start correctly?
I never did find what was causing this issue.
It got to a point where I could deploy from my machine and not get the problem, but my colleague could not.
We tried comparing the contents of the .cspkg files that were produced, but didn't find any differences.
We are now both able to deploy the project with no problems.
My suspicion is that this was resolved when we upgraded the Azure SDK and tools on our machines.

WCF RIA Services Domain Service not found when debugging with Windows Azure cloud project

I am trying to debug a Windows Azure Cloud project locally with Visual Studio 2012 running the Windows Azure SDK 1.7 on a Windows 8 PC with IIS 8 Express. The cloud project includes a Web Role running an ASP.NET MVC 3.0 web project that includes WCF RIA Services that in turn links to a Silverlight project hosted on that web site. When I run the web site directly and do not try to debug the Azure cloud project I am able to access the web site and the Silverlight application and the RIA Services are accessible with absolutely no issues. If however I debug the Azure Cloud project the emulators start up and the web site comes up. I am able to then access the Silverlight application but when it tries to make a request back to the WCF RIA Services Domain Service I receive an error from the IIS Server stating that the domain service is not available. I then try to go directly against the WCF RIA Service endpoint to see if it will come up outside the Silverlight application and again I receive a 404 Not Found response when going to the *.svc endpoint.
I have gone through various searches to try and resolve the issue and I have used Fiddler to ensure the network requests are not having any issues. I have not been able to identify any problems. I also tried turning on WCF tracing to see if any errors comes up, but the trace files are not even updated when I debug through the Azure Cloud project.
After repeatedly getting this behavior I have attempted a complete re-install of Visual Studio 2012 and the Azure 1.7 SDK, but I still get the same behavior. Does anyone have a suggestion of what the issue may be or how I might try and track down the issue, since the WCF tracing is not offering me any additional information?
Strange. Could you try this sample project, which is quickly created with VS2012 on W8 using IIS8 Express, .NET 4.0, MVC3 hosting Domain Service and Silverlight consuming that domain service. Everything works just fine.
If that project runs at your environment fine - then it might be some missconfiguration of your web.config/global.asax file. If that project also fails in your environment - then it might be something very messy with the environment.

Access Azure Development Server From VM?

We are developing an application that we are deploying to Azure. It needs to work with a specific machine configuraiton. We we have this configured as a VM which developers can run locally.
However to test the VM configuration we need to publish to Azure and access it on a live Azure instance. Is there anyway to allow a local VM to get access to the Azure environment IIS on the developers machine? It doesn't seem to show up in IIS Express so I guess it isn't the same as a normal site?
Also is it possible to configure an Azure environment locally for testing. We want to host test applications for internal use and don't want them run on developers machines. We would like to run them on a server in the office.
Any ideas?
Thanks
I think that the answer to this question will outline the general guidelines you could follow to enable your environment.
Windows Azure Emulator has its own load balancer simulator which bind to socket 127.0.0.1:81 (most of the cases, if port 81 is free). If the Azure project is developed with Azure SDK 1.3 or later with Full IIS enabled, then the Azure Emulator (for versions 1.3 ~ 1.6) will use local IIS to host the sites. IIS Express is not involved in any way with the Azure project. If you happen to run IIS Express, then most probably you have set up your web application project as a StartUp project in the solution. The correct way to locally debug Windows Azure applications is to use the Cloud Project as a startup project.
Please kindly update your question, if there is some doubt or confusion after checking the mentioned related question.

Resources