emo
emo

Reputation: 43

Why am I getting a 404 error for my code-behind on Azure?

I'm posting and answering my own question in case it helps someone else - I just spend several hours trying to figure out why I was getting a 404 error for the code-behind of an ASPX page. We had converted an existing web site to a web application and published to Azure. The web page worked properly during testing on localhost (IIS-Express), but threw the 404 error when running on Azure.

Upvotes: 1

Views: 272

Answers (2)

rainhamtown
rainhamtown

Reputation: 171

A 404 error means that the resource cannot be found. Are you trying to load a page with localhost in the url?

Also this could be a relative path issue try opening fiddler or looking in the developer tools (F12) console window to see whether the being sent url is correct. In that it matches the root of your site.

Upvotes: 0

emo
emo

Reputation: 43

I noticed that there was no designer file, and after several unsuccessful attempts I gave up and created a new ASPX page, copy/pasted my code, deleted the original, and renamed the new file. Having a designer file didn't solve the issue, but one of the posted answers helped.

When a web site project is converted to a web application project, the "CodeFile" attribute in the Page directive must be changed to "CodeBehind".

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="TestPage.aspx.cs" Inherits="TestPage" %>

Visual Studio does that for you when you convert the project, but it missed this page and a few others. In retrospect, I would have expected a build error or some type of warning from Visual Studio, but maybe the "CodeFile" attribute is valid in a web application.

Upvotes: 1

Related Questions