Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-core/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 找不到网站地址AzureWeb的网页_C#_Asp.net Core_Azure Web App Service - Fatal编程技术网

C# 找不到网站地址AzureWeb的网页

C# 找不到网站地址AzureWeb的网页,c#,asp.net-core,azure-web-app-service,C#,Asp.net Core,Azure Web App Service,我将应用程序部署到Azurewebsite,在测试应用程序时发现一个错误。 当我想将产品添加到袋子时,袋子不会显示产品已添加,当我按下袋子图标时,显示错误 This granihouse.azurewebsites.net page can’t be found No webpage was found for the web address: https://granihouse.azurewebsites.net/Customer/ShoppingCart HTTP ERROR 404 到

我将应用程序部署到Azurewebsite,在测试应用程序时发现一个错误。 当我想将产品添加到袋子时,袋子不会显示产品已添加,当我按下袋子图标时,显示错误

This granihouse.azurewebsites.net page can’t be found No webpage was found for the web address: https://granihouse.azurewebsites.net/Customer/ShoppingCart
HTTP ERROR 404
到目前为止,我所做的是,我尝试在本地主机IIS上部署应用程序,并使用FileZilla获取文件并传输到服务器,但什么都没有改变。 我做的第二件事是尝试更改连接字符串,并尝试在VisualStudio中部署应用程序,但遇到了相同的问题

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using GraniteHouse.Data;
using GraniteHouse.Extensions;
using GraniteHouse.Models;
using GraniteHouse.Models.ViewModel;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;

namespace GraniteHouse.Areas.Customer.Controllers
{
    [Area("Customer")]
    public class ShoppingCartController : Controller
    {
        private readonly ApplicationDbContext _db;

        [BindProperty]
        public ShoppingCartViewModel ShoppingCartVM { get; set; }

        public ShoppingCartController(ApplicationDbContext db)
        {
            _db = db;
            ShoppingCartVM = new ShoppingCartViewModel()
            {
                Products = new List<Models.Products>()
            };
        }

        //Get Index Shopping Cart
        public async Task<IActionResult> Index()
        {
            List<int> lstShoppingCart = HttpContext.Session.Get<List<int>>("ssShoppingCart");
            if(lstShoppingCart.Count > 0)
            {
                foreach(int cartItem in lstShoppingCart)
                {
                    Products prod = _db.Products.Include(p => p.SpecialTags).Include(p => p.ProductTypes).Where(p => p.Id == cartItem).FirstOrDefault();
                    ShoppingCartVM.Products.Add(prod);
                }
            }
            return View(ShoppingCartVM);
        }

        [HttpPost]
        [ValidateAntiForgeryToken]
        [ActionName("Index")]
        public IActionResult IndexPost()
        {
            List<int> lstCartItem = HttpContext.Session.Get<List<int>>("ssShoppingCart");

            ShoppingCartVM.Appointments.AppointmentDate = ShoppingCartVM.Appointments.AppointmentDate
                                                                        .AddHours(ShoppingCartVM.Appointments.AppointmentTime.Hour)
                                                                        .AddMinutes(ShoppingCartVM.Appointments.AppointmentTime.Minute);
            Appointments appointments = ShoppingCartVM.Appointments;
            _db.Appointments.Add(appointments);
            _db.SaveChanges();

            int appointmentId = appointments.Id;

            foreach (int productId in lstCartItem)
            {
                ProductsSelectedForAppointment productSelectedForAppointment = new ProductsSelectedForAppointment()
                {
                    AppointmentId = appointmentId,
                    ProductId = productId

                };
                _db.ProductsSelectedForAppointment.Add(productSelectedForAppointment);

            }
            _db.SaveChanges();
            lstCartItem = new List<int>();
            HttpContext.Session.Set("ssShoppingCart", lstCartItem);

            return RedirectToAction("AppointmentConfirmation", "ShoppingCart", new { Id = appointmentId});
        }



        public IActionResult Remove(int id)
        {
            List<int> lstCartItem = HttpContext.Session.Get<List<int>>("ssShoppingCart");

            if(lstCartItem.Count > 0)
            {
                if(lstCartItem.Contains(id))
                {
                    lstCartItem.Remove(id);
                }
            }
            HttpContext.Session.Set("ssShoppingCart", lstCartItem);

            return RedirectToAction(nameof(Index));
        }


        //Get
        public IActionResult AppointmentConfirmation(int id)
        {
            ShoppingCartVM.Appointments = _db.Appointments.Where(a => a.Id == id).FirstOrDefault();
            List<ProductsSelectedForAppointment> objProdList = _db.ProductsSelectedForAppointment.Where(p => p.AppointmentId == id).ToList();


            foreach(ProductsSelectedForAppointment prodAtpObj in objProdList)
            {
                ShoppingCartVM.Products.Add(_db.Products.Include(p => p.ProductTypes).Include(p => p.SpecialTags).Where(p => p.Id == prodAtpObj.ProductId).FirstOrDefault());
            }
            return View(ShoppingCartVM);
        }
    }
}
使用系统;
使用System.Collections.Generic;
使用System.Linq;
使用System.Threading.Tasks;
使用GraniteHouse.数据;
使用花岗岩房屋。扩建;
使用GraniteHouse.模型;
使用GraniteHouse.Models.ViewModel;
使用Microsoft.AspNetCore.Mvc;
使用Microsoft.EntityFrameworkCore;
命名空间:ehouse.Areas.Customer.Controllers
{
[区域(“客户”)]
公共类ShoppingCartController:控制器
{
私有只读应用程序dbContext_db;
[BindProperty]
公共ShoppingCartViewModel ShoppingCartVM{get;set;}
公共购物车控制器(ApplicationDbContext数据库)
{
_db=db;
ShoppingCartVM=新的ShoppingCartViewModel()
{
产品=新列表()
};
}
//获取索引购物车
公共异步任务索引()
{
List lstShoppingCart=HttpContext.Session.Get(“ssShoppingCart”);
如果(lstShoppingCart.Count>0)
{
foreach(lstShoppingCart中的int cartItem)
{
Products prod=\u db.Products.Include(p=>p.SpecialTags).Include(p=>p.ProductTypes).Where(p=>p.Id==cartItem).FirstOrDefault();
ShoppingCartVM.Products.Add(prod);
}
}
返回视图(ShoppingCartVM);
}
[HttpPost]
[ValidateAntiForgeryToken]
[行动名称(“索引”)]
public IActionResult IndexPost()
{
List lstCartItem=HttpContext.Session.Get(“ssShoppingCart”);
ShoppingCartVM.Appointments.AppointmentDate=ShoppingCartVM.Appointments.AppointmentDate
.AddHours(ShoppingCartVM.appoints.AppointmentTime.Hour)
.AddMinutes(ShoppingCartVM.appointment.AppointmentTime.Minute);
约会=ShoppingCartVM.约会;
_db.任命。添加(任命);
_db.SaveChanges();
int appointmentId=appoints.Id;
foreach(lstCartItem中的int productId)
{
Products Selected ForAppoims Products Selected ForAppoims=新产品Selected ForAppoims()
{
任命ID=任命ID,
ProductId=ProductId
};
_db.products selected for appoims.Add(products selected for appoims);
}
_db.SaveChanges();
lstCartItem=新列表();
HttpContext.Session.Set(“ssShoppingCart”,lstCartItem);
返回重定向操作(“AppointConfirmation”,“ShoppingCart”,new{Id=appointmentId});
}
公共IActionResult删除(内部id)
{
List lstCartItem=HttpContext.Session.Get(“ssShoppingCart”);
如果(lstCartItem.Count>0)
{
if(项目包含(id))
{
lstCartItem.Remove(id);
}
}
HttpContext.Session.Set(“ssShoppingCart”,lstCartItem);
返回重定向到操作(名称(索引));
}
//得到
公共IActionResult任命确认(内部id)
{
ShoppingCartVM.Appoints=_db.Appoints.Where(a=>a.Id==Id.FirstOrDefault();
List objProdList=_db.productsSelectedforappoint.Where(p=>p.AppointmentId==id).ToList();
foreach(在objProdList中为应用产品选择的产品)
{
ShoppingCartVM.Products.Add(_db.Products.Include(p=>p.ProductTypes).Include(p=>p.SpecialTags).Where(p=>p.Id==prodAtpObj.ProductId).FirstOrDefault());
}
返回视图(ShoppingCartVM);
}
}
}
看起来Azure无法识别ShoppingCart控制器。
有什么问题吗?

如果您的站点在本地运行良好,我会检查您的依赖项是如何配置的。当我访问时,我收到一个超时错误。假设您在Visual Studio中使用的是右键单击发布,我认为
ApplicationDbContext
指向您的应用程序服务的内容存在问题。另外,
lstShoppingCart
可能为空,这意味着在检查
时可能会抛出NullReferenceException。在这种情况下,您的视图将不会返回。

您正在部署已发布的内容还是源代码?我的网站的内容在此链接中,您可以在底部部分“我知道如何发布”中看到如何部署到azure,但我在Azure上使用应用程序时出错。你认为这个错误来自部署吗?你发布到azure的方式有些问题。您可能遗漏了几个步骤,但当我按Add to Bag按钮时,它应该将Bag增加到(1),但这并没有发生,当我按Bag View时,它的显示为NullReferenceException我假设Bag是
HttpContext.Session.Get(“ssShoppingCart”)HttpContext.Session[“ssShoppingCart”]
?我没有设置它。一旦我运行了应用程序,它就可以正常工作,运行几次后,我会得到运行时错误。NullReferenceException如果您没有设置它,那么这就是导致NullReferenceException的原因。你能做的一件事就是