I'm experiencing an error when I deploy my ASP.NET project to a web app service in Azure. I can't replicate it when running my code in the local development environment/web server (IIS).
To give some background, the particular page I'm struggling with is the newest page I've added to the project; all other pages work fine. I am doing a bit of query-string passing, but even without passing the query string in the URL, I'm seeing the same error.
Error:
The resource you are looking for has been removed, had its name changed, or is temporarily unavailable.
Here's the code of the page that's not working (.aspx):
<%@ Page Title="Car Photos" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true" CodeFile="CarImages.aspx.cs" Inherits="CarImages" %>
<asp:Content ID="Content1" ContentPlaceHolderID="MainContent" Runat="Server">
<customControls:Header runat="server" heading="Car Photos"></customControls:Header>
<div class="row">
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings: MYCONNSTRING %>"
SelectCommand="SELECT CarImages.CarImage, CarImages.CarName, Cars.CarID, Cars.Model FROM CarImages INNER JOIN Cars ON CarImages.CarID = Cars.CarID WHERE (Cars.CarID = CarImages.CarID)">
<SelectParameters>
<asp:QueryStringParameter Name="CarID" QueryStringField="CarID" Type="Int32" />
</SelectParameters>
</asp:SqlDataSource>
<asp:Label ID="ErrorLabel" runat="server" Text=""></asp:Label>
<br />
<br />
<asp:Image ID="Image1" runat="server" Height="284px" Width="432px"/>
<br /><br /><br /><br />
</div>
</asp:Content>
... and the code behind (.aspx.cs):
public class MyClass
{
public string ImagePath { get; set; }
public int Id { get; set; }
public string Name { get; set; }
}
public partial class CarImages : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
string queryStringId = (Request.QueryString["CarID"]).ToString();
int queryStringIdNum = Int32.Parse(queryStringId);
SqlConnection con = new SqlConnection("Data Source=SECRETSERVER.database.windows.net;Initial Catalog=SECRETDB;User ID=SECRET;Password=SECRET");
SqlCommand sql = new SqlCommand(@"SELECT CarID, CarImage, CarName FROM CarImages WHERE CarID = @queryStringIdNum", con);
sql.Parameters.AddWithValue("@queryStringIdNum", queryStringIdNum);
con.Open();
//using(var command = sql)
//{
using (var reader = sql.ExecuteReader())
{
var list = new List<MyClass>();
while (reader.Read())
list.Add(new MyClass
{
ImagePath = reader.GetString(1),
Id = reader.GetInt32(0),
Name = reader.GetString(2)
});
bool isEmpty = !list.Any();
if (isEmpty)
{
ErrorLabel.ForeColor = Color.Red;
ErrorLabel.Text = "No images currently uploaded. Please check back later";
Image1.Visible = false;
}
else
{
ErrorLabel.ForeColor = Color.Green;
ErrorLabel.Text = "Image found!";
foreach (var img in list)
{
Image1.ImageUrl = img.ImagePath;
}
}
}
}
}
I appreciate anyone with a bit of insight. I'm struggling to determine what might be causing this, since it works fine in the local webserver (ie building and testing from VS 2017). Thanks all!
The resource you are looking for has been removed, had its name changed, or is temporarily unavailable.
It is a 404 Not Found error. It means the page which you requested is not found by your server. There are two reasons that can cause this problem.
The path to access this page should be like this, we need to put the folder name in front of the page name.
http://yourwebsitename.azurewebsites.net/car/CarImages.aspx?CarID=1
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.