我将应用程序部署到Azurewebsite,并且在测试应用程序时发现一个错误。 当我想将产品添加到Bag时,Bag不会显示已添加产品,而当我按Bag的图标时,它会显示错误
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
到目前为止,我所做的是,我尝试在localhost IIS上部署应用程序,并使用FileZilla接收文件并将其传输到服务器,并且没有发生任何变化。 我所做的第二件事是尝试更改连接字符串,并尝试在Visual Studio中部署应用程序,但是同样存在同样的问题。
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);
}
}
}
Azure似乎无法识别ShoppingCart控制器。 有什么建议是什么问题吗?
答案 0 :(得分:0)
如果您的站点在本地运行良好,我将检查如何配置依赖项。当我访问https://granihouse.azurewebsites.net/时,我收到超时错误。假设您在Visual Studio中使用右键单击发布,那么我认为ApplicationDbContext
指向您的应用程序服务存在问题。另外,lstShoppingCart
可以为null,这意味着在检查.Count
时会抛出NullReferenceException,在这种情况下,不会返回您的View。