当我将ASP.NET项目部署到Azure中的Web应用程序服务时,我遇到了错误。在本地开发环境/ Web服务器(IIS)中运行代码时,我无法复制它。
为了给出一些背景知识,我所挣扎的特定页面是我已添加到项目中的最新页面;所有其他页面工作正常。我正在做一些查询字符串传递,但即使没有在URL中传递查询字符串,我也看到了相同的错误。
错误:
您要查找的资源已被删除,名称已更改或暂时不可用。
这里的页面代码不起作用(.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>
...和背后的代码(.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;
}
}
}
}
}
我很欣赏任何有点洞察力的人。我正在努力确定可能导致这种情况的原因,因为它在本地网络服务器中工作正常(即从VS 2017构建和测试)。谢谢大家!
答案 0 :(得分:0)
您要查找的资源已被删除,名称已更改或暂时不可用。
这是404 Not Found错误。这意味着您的服务器找不到您请求的页面。导致此问题的原因有两个。