簡體   English   中英

找不到網址Azurewebsite的網頁

[英]No webpage was found for the web address Azurewebsite

我將應用程序部署到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

到目前為止,我所做的就是嘗試使用FileZilla在localhost IIS上部署應用程序並獲取文件並將其傳輸到服務器,並且沒有任何變化。 我所做的第二件事是嘗試更改連接字符串,並嘗試在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控制器。 有什么建議可能是問題嗎?

如果您的站點在本地運行良好,我將檢查如何配置依賴項。 當我訪問https://granihouse.azurewebsites.net/時,我收到超時錯誤。 假設您在Visual Studio中使用右鍵單擊發布,那么我認為ApplicationDbContext指向您的應用程序服務存在問題。 另外, lstShoppingCart可以為null,這意味着在檢查.Count時可能會拋出NullReferenceException,在這種情況下,不會返回您的View。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM