[英]ASP.NET Web Forms - Deploying to Azure - “The resource you are looking for has been removed or is temporarily unavailable.”
I'm experiencing an error when I deploy my ASP.NET project to a web app service in Azure. 我将ASP.NET项目部署到Azure中的Web应用程序服务时遇到错误。 I can't replicate it when running my code in the local development environment/web server (IIS).
在本地开发环境/ Web服务器(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.
我正在做一些查询字符串传递,但是即使没有在URL中传递查询字符串,我也会看到相同的错误。
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): 这是无法使用的页面代码(.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): ...以及(.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).
我正在努力确定可能是什么原因造成的,因为它在本地Web服务器中运行良好(即从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. 这是404找不到错误。 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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.