'/'应用程序中的服务器错误。无法找到该资源。怎么解决? [英] Server Error in '/' Application. The resource cannot be found. How to fix it?

查看:783
本文介绍了'/'应用程序中的服务器错误。无法找到该资源。怎么解决?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Server Error in '/' Application.
--------------------------------------------------------------------------------

The resource cannot be found. 
Description: HTTP 404. The resource you are looking for (or one of its dependencies) could have been removed, had its name changed, or is temporarily unavailable.  Please review the following URL and make sure that it is spelled correctly. 

Requested URL: /Admin/~Admin/AddNewProducts.aspx


--------------------------------------------------------------------------------
Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.18408 





源代码



Source code

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using ShoppingProject.BusinessLayer;
 
namespace ShoppingProject.Admin
{
    public partial class AddNewProducts : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                GetCategories();
 
                AddSubmitEvent();
 
                if (Request.QueryString["alert"] == "success")
                {
                    Response.Write("<script>alert('Record Saved Successfully.');</script>");
                }
            }
 
        }
 
        private void AddSubmitEvent()
        {
            UpdatePanel updatePanel = Page.Master.FindControl("AdminUpdatePanel") as UpdatePanel;
            UpdatePanelControlTrigger trigger = new PostBackTrigger();
            trigger.ControlID = btnSubmit.UniqueID;
 
            updatePanel.Triggers.Add(trigger);
        }
 
        private void GetCategories()
        {
            ShoppingCart k = new ShoppingCart();
            DataTable dt = k.GetCategories();
            if (dt.Rows.Count > 0)
            {
                ddlCategory.DataValueField = "CategoryID";
                ddlCategory.DataTextField = "CategoryName";
                ddlCategory.DataSource = dt;
                ddlCategory.DataBind();
            }
        }
 
        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            if (uploadProductPhoto.PostedFile != null)
            {
                SaveProductPhoto();
 
                ShoppingCart k = new ShoppingCart()
                {
                    ProductName = txtProductName.Text,
                    ProductPrice = txtProductPrice.Text,
                    ProductImage = "~/ProductImages/" + uploadProductPhoto.FileName,
                    ProductDescription = txtProductDescription.Text,
                    CategoryID = Convert.ToInt32(ddlCategory.SelectedValue),
                    TotalProducts = Convert.ToInt32(txtProductQuantity.Text)
                };
                k.AddNewProduct();
                // Alert.Show("Record Seved Successfully");
                ClearText();
                Response.Redirect("~Admin/AddNewProducts.aspx?alert=success");
 
            }
            else
            {
                //Alert.Show("Upload Product Photo");
                Response.Write("<script>alert('Please UpLoad Photo');</script>");
            }
 
        }
 
        private void ClearText()
        {
            uploadProductPhoto = null;
            txtProductName.Text = string.Empty;
            txtProductPrice.Text = string.Empty;
            txtProductDescription.Text = string.Empty;
            txtProductQuantity.Text = string.Empty;
        }
 
        private void SaveProductPhoto()
        {
            if (uploadProductPhoto.PostedFile != null)
            {
                string filename = uploadProductPhoto.PostedFile.FileName.ToString();
                string fileExt = System.IO.Path.GetExtension(uploadProductPhoto.FileName);
 
                //check file name length
                if (filename.Length > 96)
                {
                    //Alert.Show("image name should not exceed 96 character !");
                }
                //check filetype
                else if (fileExt != ".jpeg" && fileExt != ".jpg" && fileExt != ".png" && fileExt != ".bmp")
                {
                    //Alert.Show("Only jpeg,jpg,bmp & png imags are allowed!");
                }
 
                //check file size
                else if (uploadProductPhoto.PostedFile.ContentLength > 4000000)
                {
                    //Alert.Show("image size should not be greater than 4MB !");
                }
                //Save images into Images folder
                else
                {
                    uploadProductPhoto.SaveAs(Server.MapPath("~/ProductImages/" + filename));
                }
 
            }
        }
    }
}

推荐答案

问题出在URL本身的某个地方。您确保该页面确实存在,但不是在指定的位置。您尝试访问的位置是/Admin/ ~Admin/AddNewProducts.aspx。那么在那个位置,你确定,第二个~Admin /是必需的吗?



我认为有效的URL是这样的:/Admin / AddNewProducts.aspx。确保该位置存在文件。 ASP.NET不会打扰为您添加或删除目录。这不是它的作用。
The problem would be somewhere with the URL itself. You have made sure that the page does exist, but not at the location specified. The location that you are trying to access is, "/Admin/~Admin/AddNewProducts.aspx". So in that location, are you sure, second "~Admin/" is required?

What I think is a valid URL would be something like this: "/Admin/AddNewProducts.aspx". Make sure that the files exist at the location. ASP.NET won't bother adding or removing directories for you. That is not what it does.


这篇关于'/'应用程序中的服务器错误。无法找到该资源。怎么解决?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆