404 error on azure for Asp.Net Web Api Project - asp.net-mvc

I have deployed exact same solution on two servers, one is my own server in my basement and the other one is Microsoft Azure. The project is developed using Asp.Net Web Api 2.
On my own windows server running IIS 8.5 it totally works. For test, you can simply browse this link in your browser and see the error message {"Message":"The requested resource does not support http method 'GET'."} which shows the API has been hit.1
But exact same project on my Azure domain here, you just get a message saying
The resource you are looking for has been removed, had its name
changed, or is temporarily unavailable.
Everything about these two deployments is the same (to the best of my knowledge) and I was wondering if there is any further steps necessary on Web Api app deployment in MS Azure which I am missing.

I finally found the answer to this issue. If there are multiple apps deployed as one single website so each app is located in its own subfolder, you have to go to the configuration section of your web app on Azure and create virtual directories for each of those sub folders.

Ah, my problem was probably a common one. I was using
rootconfig = System.Web.Configuration.WebconfigurationManager.OpenWebConfiguration(null);
and that was returning the root web because the parameter was null.
When I ran it local that worked fine, but after I deployed the root Config was NOT what I wanted and my code was failing.
Switched to direct access via
stringVal = WebconfigurationManager.AppSettings["Foobar"].ToString();
Nice. Plus less overhead.

Related

How to change Machine Key generated by Visual Studio ASP.NET MVC Project?

I'm working on an ASP.NET MVC Web App with Office 365 authentication. The web app runs perfectly on my computer, but when I transfer and run the project on other computers and on Azure, it gave me a Cryptographic Operation Error. After some research, I concluded that the Machine Keys are the ones causing the problem.
I have found the MachineKey for the Azure Web App Service, but when I put it in my local Web.Config, it still looks for my computer's original Machine Key. The same happens when I set it to auto-generate, both my computer and Azure throw the same error.
I need a way to reset the Machine Key my application is looking for. For example, if I set the Machine Key in Web.config to "KEY_EXAMPLE_HERE", my application will start to use that key. That way, I can set up the same Machine Key in all servers I need to run my application.
I don't know if the application looks for the key it generated when I created the Visual Studio project, but I need a way to change it.
Any help will be appreciated, thanks!

External HTTP requests from MVC application fail

I'm having problems making HTTP requests from my MVC.Net Intranet application. I encountered the problem when using the RestSharp library, but have boiled it down to a much simpler repro.
The following code:
using (var client = new WebClient())
{
var contents = client.DownloadString("http://www.google.com");
}
Will run successfully (on my local machine, debugging from Visual Studio 2013) inside a console app.
Will run successfully (on my local machine) from within LinqPad
Times out (on my local machine, debugging from Visual Studio 2013, hosted with IIS Express) when run from a controller action in a MVC intranet app.
This may be a duplicate of Not able to connect to website URLs from Asp.Net WebApi Action Methods (and is where I got the boiled down proof-of-problem code above) but in my case this is all running locally on my computer and it works fine from a console app.
I've tried various different code snippets, including using HttpClient instead of WebClient:
using(System.Net.Http.HttpClient c = new System.Net.Http.HttpClient())
{
var msg = c.GetAsync("http://www.google.com").Result.Content.ReadAsStringAsync().Result;
}
But I get the same, or similar results and errors in all cases. For the code above, I eventually get a 'TaskCancelled' exception, with no Inner Exception.
I've also got colleagues to try the same on their own machines, with the same results. I have read some similar questions, where people talk about problems with deadlock due to the SyncronizationContext in ASP applications, but that seems to relate to asynchronous calls. Here, as far as I can tell, everything I am doing is synchronous so I can't see how that applies.
In reality, I'm using the RestSharp library, which I've used to create a client library of my own for talking to the facebook API. I had tested this from a console app test-harness, which worked perfectly, but it all times out when I start using it inside my MVC app.
Has anyone seen this before and have any ideas on where I'm going wrong, or what the issue might be?
Is it to do with locking / deadlocking?
Could it be to do with permissions / proxy? We have quite strict web proxy rules at work, which are obviously configured correctly for my user. Could IIS Express hosting be changing the permissions or the user assigned to the app? The IIS Express service is running with my username at present.
UPDATE
I have tinkered some more and tried accessing an internal company web page instead of an external page (Google). I find that this works immediately - so that suggests strongly that it's to do with permissions or proxy settings.
Can anyone explain why this would be different between a console app and a MVC application?
UPDATE 2
I've run Fiddler to check the request and see what was happening to it. When fiddler is running the request succeeds.
This makes me think it's some strange permissions issue possibly? As a security measure, our login accounts don't have admin rights, instead we have a separate non-interactive account with admin permissions we can use to run apps that need admin rights, or install software etc. To get fiddler to capture traffic, I have to run it with this account.
Still, the calls work fine with my own normal account from the console app or LinqPad - so I guess my question becomes:
For an asp / MVC app locally hosted via IIS Express (Visual Studio Debugging), what user will this be run as, and what differences (if any) would there be to a console app?

Azure cloud service publishing - where does it go?

I created an asp.net mvc project in VS. I created an azure cloud service. Within the VS solution I added an azure project to enable me to publish to my cloud service. The cloud service has a web role and it’s published to a production environment. When I publish the project, I have my domain .cloudapp.net and I can then view my published project from a browser.
Job done. All good so far.
What I’m unclear on (and this is partly because my azure and asp.net mvc knowledge is limited) is where the project files actually reside (and the file/folder structure) and how to access them? I know they are on an IIS server somewhere but that’s about it.
With ‘traditional’ websites you have a webserver, a wwwroot folder and you stick your web pages etc into them and can see/access them through ftp etc.
Apart from wanting to know the answer to the above question I actually want to farm out the web ui (view) part to a web developer whilst I concentrate on the back end stuff. He doesn’t have visual studio so I’m unclear on how to best approach this?
I’ve noticed on the windows azure publish summary within my solution that you can enable remote desktop and enable web deploy which I suspect may be of help to me but as the solution is all working fine at the moment and I’m demoing it to a client tomorrow I’m a bit reluctant to make any last minute changes..as I’m sure we’ve all suffered the consequences of that before.
What I’m unclear on is where the project files actually reside
(and the file/folder structure) and how to access them?
As you have mentioned, these files reside on the server itself. If you connect to your server via Remote Desktop, you can see the files under D:\sitesroot folder (actual name of the folder can be found by launching IIS Manager on that server).
Having said that, it is not recommended to make changes to the files directly on the server. This is because if your server goes bad for any reason, Microsoft will provision a new server for you and it takes the code from the package file when you last deployed your application. This the changes you have made on that server will be lost.
Regarding your other question about having somebody focus on front-end development, I'm pretty sure you don't want him to working on production server directly. I'm assuming you have a centralized code repository somewhere where everybody checks in their code and then you build stuff and then deploy it.

Deploying ASP.NET Web API App to IIS 7 On Different Server

I have been literally stuck for hours trying to deploy a Web API app to IIS. I can not believe there are no useful tutorials online anywhere that I can find. Here is my situation.
I have a VERY basic Web API app. It is using .NET Framework 4.0. It doesn't do anything I just want to see the home page at this point.
I am developing it in Visual Studio 2012 on my local machine. I can hit my localhost and see the home page, even post some data through Fiddler works great.
I publish the solution using Build->Publish to my local file system.
I then copy and paste everything in that directory to my web server (actually using a repository but for simplicity sake)
I created a brand new application pool in IIS. .NET 4.0 Integrated.
I placed the folder that contains my published code inside of the directory of my main website. The folder name is WebAPI.
I created a new website in IIS, attached to that new app pool I created.
I start the website, browse it on localhost and everything works perfectly.
I try to go to the website externally "website.com/WebAPI/api" and get a
403.14 - Forbidden The Web server is configured to not list the contents of this directory.
I'm sure I'm doing something wrong, I've never deployed an MVC app to IIS on another server. I'm able to deploy it just fine on my local machine through IIS too. What am I missing? Thanks!
Edit: Yes, my server has other .NET 4.0 apps running just fine.
http://localhost/api
http://website.com/WebAPI/api
Is this correct?
If so, looks like it could be a path problem.

Umbraco 6 on Azure: UmbracoModule Service Unavailable

I'm deploying a new Umbraco 6 installation to Azure, and I've run into a problem I can't seem to diagnose.
Here are the steps I took to get the site deployed:
Created new MVC 4 project in VS2012
Installed UmbracoCms 6.0.0 via NuGet
Tested locally: SUCCESS
Set up correct connection string for Azure in Web.config (via transform)
Deployed to Azure using Web Deploy
Unfortunately, when I navigated to the Azure instance, I get a blank page with "The service is unavailable." I enabled detailed logging in Azure, and looked at the log files. There wasn't much that suggested a solution to me. This is what the detailed error says:
Module: UmbracoModule
Notification: ResolveRequestCache
Handler: PageHandlerFactory-Integrated-4.0
Error Code: 0x00000000
I'm out of ideas at this point...any ideas?
I've just gone through the steps of what you describe. I created a MVC4 project and downloaded Umbraco 6 via Nuget. What I did notice was that I had to 'include' a fair number of file into the project structure in the VS solution explorer.
I ran the website locally and ran an install just using SQL CE.
I created a website on Azure and I downloaded the .PublishSettings file and imported this into the Web Deploy options in VS. I then published the site 'as is' just to see what happened. I didn't expect the database to work but I just wanted to make sure that the application ran ok and I could at least access the Umbraco login screen.
When I accessed the site, it worked as expected and I could access the login screen at /umbraco/
Given the problems you are having, although this sounds simple, did you 'include' all the files in the solution explorer before deploying?
If you are still having issues, I would doing what I have done and just setting up another very simple site to test your deployment process. I have to be honest, I was surprised how easy it is.
I've just been through the same steps with the simple blog and it was quite hard. I didn't include anything into Visual Studio (except it's 2010 and I downloaded the publish profile) and the site ran fine locally.
On uploading Umbraco 6 to azure I got 'Could not load file or assembly MySql.Data, ' etc. .net error. Of course, it was there.
On repeating my deployment steps, swapping between Visual Studio, Web Matrix and Sql Azure Migration Wizard, checking it was release config on build etc. (not that it should need building) I got various 'The page cannot be displayed because an internal server error has occurred' on a blank white screen, and 'Could not load My.Sql' errors.
Coming back to it the next day, I deployed again, and my user had lost its role membership in the database. I ran the EXEC sp_addrolemembers again, and lo, the site now works. I wish I could be more specific on what went wrong and what got fixed, but it's all a bit voodoo.
I second what Digby said - make sure all your includes are, well, included and keep on deploying. I think azure is having a bit of a do lately, there was an outage last week on 23rd Feb.

Resources