【发布时间】:2019-04-18 07:02:59
【问题描述】:
我将应用程序部署到 Azure 网站,在测试应用程序时发现了一个错误。 当我想将产品添加到 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
到目前为止,我所做的是尝试在本地 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 控制器。 有什么建议吗?
【问题讨论】:
-
您是在部署已发布的内容还是源代码?
-
我的网站内容
-
c-sharpcorner.com/article/… 在此链接中,您可以在底部看到如何部署到 azure
-
我知道如何发布,但在 Azure 上使用应用程序时出现错误。您认为该错误来自部署?
-
您发布到 azure 的方式有问题。您可能遗漏了几个步骤
标签: c# asp.net-core azure-web-app-service