将带有类库的ASP.Net Core Web App发布到Azure时,在主页上出现500错误

时间:2018-05-24 19:06:40

标签: c# azure asp.net-core azure-web-app-service

我一直在尝试将我的Web应用程序部署到Azure,但在第一页上出现500错误。我假设这是因为我在第一页上引用的模型存在问题,该模型在我的解决方案中被引用到类库中。 这是项目的外观

Here's how the project looks.

我之前在引用类库方面遇到了一些问题,但到目前为止,我已经能够解决这些问题并成功构建这两个项目。该项目在IISExpress中运行良好。但是当我尝试将其部署到Azure时,我的主页上出现了500错误。这是代码:

@using LNCLibrary.Models.HomeViewModel
@model HomeViewModel
@{
    ViewData["Title"] = "Home Page";
}
@inject SignInManager<ApplicationUser> SignInManager
@inject UserManager<ApplicationUser> UserManager
<!--
Au<!--
Author: W3layouts
Author URL: http://w3layouts.com
License: Creative Commons Attribution 3.0 Unported
License URL: http://creativecommons.org/licenses/by/3.0/
-->
<!DOCTYPE HTML>
<html>
<head>
    <title>New Shop a E-Commerce Online Shopping Category Flat Bootstrap Responsive Website Template | Home :: w3layouts</title>
    <!--css-->
    <link href="css/bootstrap.css" rel="stylesheet" type="text/css" media="all" />
    <link href="css/style.css" rel="stylesheet" type="text/css" media="all" />
    <link href="css/font-awesome.css" rel="stylesheet">
    <!--css-->
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta name="keywords" content="New Shop Responsive web template, Bootstrap Web Templates, Flat Web Templates, Android Compatible web template,
Smartphone Compatible web template, free webdesigns for Nokia, Samsung, LG, SonyEricsson, Motorola web design" />
    <script type="application/x-javascript"> addEventListener("load", function() { setTimeout(hideURLbar, 0); }, false); function hideURLbar(){ window.scrollTo(0,1); } </script>
    <script src="js/jquery.min.js"></script>
    <link href='//fonts.googleapis.com/css?family=Cagliostro' rel='stylesheet' type='text/css'>
    <link href='//fonts.googleapis.com/css?family=Open+Sans:400,800italic,800,700italic,700,600italic,600,400italic,300italic,300' rel='stylesheet' type='text/css'>
    <!--search jQuery-->
    <script src="js/main.js"></script>
    <!--search jQuery-->
    <script src="js/responsiveslides.min.js"></script>
    <script>
        $(function () {
            $("#slider").responsiveSlides({
                auto: true,
                nav: true,
                speed: 500,
                namespace: "callbacks",
                pager: true,
            });
        });
    </script>
    <!--mycart-->
    <script type="text/javascript" src="js/bootstrap-3.1.1.min.js"></script>
    <!-- cart -->
    <script src="js/simpleCart.min.js"></script>
    <!-- cart -->
    <!--start-rate-->
    <script src="js/jstarbox.js"></script>
    <link rel="stylesheet" href="css/jstarbox.css" type="text/css" media="screen" charset="utf-8" />
    <script type="text/javascript">
        jQuery(function () {
            jQuery('.starbox').each(function () {
                var starbox = jQuery(this);
                starbox.starbox({
                    average: starbox.attr('data-start-value'),
                    changeable: starbox.hasClass('unchangeable') ? false : starbox.hasClass('clickonce') ? 'once' : true,
                    ghosting: starbox.hasClass('ghosting'),
                    autoUpdateAverage: starbox.hasClass('autoupdate'),
                    buttons: starbox.hasClass('smooth') ? false : starbox.attr('data-button-count') || 5,
                    stars: starbox.attr('data-star-count') || 5
                }).bind('starbox-value-changed', function (event, value) {
                    if (starbox.hasClass('random')) {
                        var val = Math.random();
                        starbox.next().text(' ' + val);
                        return val;
                    }
                })
            });
        });
    </script>
    <!--//End-rate-->
</head>
<body>
    <!--header-->
    <div class="header">
        <div class="header-top">
            <div class="container">
                <div class="top-left">
                    <a href="#"> Help  <i class="glyphicon glyphicon-phone" aria-hidden="true"></i> +0123-456-789</a>
                    <a asp-controller="Admin" asp-action="Index">Administration</a>
                </div>
                <div class="top-right" style="padding-right:1em;">
                    <ul>
                        @await Html.PartialAsync("_LoginPartial")
                    </ul>
                </div>
                <div class="clearfix"></div>
            </div>
        </div>
        <div class="heder-bottom">
            <div class="container">
                <div class="logo-nav">
                    <div class="logo-nav-left">
                        <h1><a href="index.html">New Shop <span>Shop anywhere</span></a></h1>
                    </div>
                    <div class="logo-nav-left1">
                        <nav class="navbar navbar-default">
                            <!-- Brand and toggle get grouped for better mobile display -->
                            <div class="navbar-header nav_2">
                                <button type="button" class="navbar-toggle collapsed navbar-toggle1" data-toggle="collapse" data-target="#bs-megadropdown-tabs">
                                    <span class="sr-only">Toggle navigation</span>
                                    <span class="icon-bar"></span>
                                    <span class="icon-bar"></span>
                                    <span class="icon-bar"></span>
                                </button>
                            </div>
                            <div class="collapse navbar-collapse" id="bs-megadropdown-tabs">
                                <ul class="nav navbar-nav">
                                    <li class="active"><a href="index.html" class="act">Home</a></li>
                                    <!-- Mega Menu -->
                                    <li class="dropdown">
                                        <a href="#" class="dropdown-toggle" data-toggle="dropdown">Women<b class="caret"></b></a>
                                        <ul class="dropdown-menu multi-column columns-3">
                                            <div class="row">
                                                <div class="col-sm-3  multi-gd-img">
                                                    <ul class="multi-column-dropdown">

                                                        <li><a href="products.html">Clothing</a></li>
                                                        <li><a href="products.html">Wallets</a></li>
                                                        <li><a href="products.html">Shoes</a></li>
                                                        <li><a href="products.html">Watches</a></li>
                                                        <li><a href="products.html"> Underwear </a></li>
                                                        <li><a href="products.html">Accessories</a></li>
                                                    </ul>
                                                </div>
                                                <div class="col-sm-3  multi-gd-img">
                                                    <ul class="multi-column-dropdown">
                                                        <h6>Submenu2</h6>
                                                        <li><a href="products.html">Sunglasses</a></li>
                                                        <li><a href="products.html">Wallets,Bags</a></li>
                                                        <li><a href="products.html">Footwear</a></li>
                                                        <li><a href="products.html">Watches</a></li>
                                                        <li><a href="products.html">Accessories</a></li>
                                                        <li><a href="products.html">Jewellery</a></li>
                                                    </ul>
                                                </div>
                                                <div class="col-sm-3  multi-gd-img">
                                                    <a href="products.html"><img src="images/woo.jpg" alt=" " /></a>
                                                </div>
                                                <div class="col-sm-3  multi-gd-img">
                                                    <a href="products.html"><img src="images/woo1.jpg" alt=" " /></a>
                                                </div>
                                                <div class="clearfix"></div>
                                            </div>
                                        </ul>
                                    </li>
                                    <li class="dropdown">
                                        <a href="#" class="dropdown-toggle" data-toggle="dropdown">Men <b class="caret"></b></a>
                                        <ul class="dropdown-menu multi-column columns-3">
                                            <div class="row">
                                                <div class="col-sm-3  multi-gd-img">
                                                    <ul class="multi-column-dropdown">

                                                        <li><a href="products.html">Clothing</a></li>
                                                        <li><a href="products.html">Wallets</a></li>
                                                        <li><a href="products.html">Shoes</a></li>
                                                        <li><a href="products.html">Watches</a></li>
                                                        <li><a href="products.html"> Underwear </a></li>
                                                        <li><a href="products.html">Accessories</a></li>
                                                    </ul>
                                                </div>
                                                <div class="col-sm-3  multi-gd-img">
                                                    <ul class="multi-column-dropdown">

                                                        <li><a href="products.html">Sunglasses</a></li>
                                                        <li><a href="products.html">Wallets,Bags</a></li>
                                                        <li><a href="products.html">Footwear</a></li>
                                                        <li><a href="products.html">Watches</a></li>
                                                        <li><a href="products.html">Accessories</a></li>
                                                        <li><a href="products.html">Jewellery</a></li>
                                                    </ul>
                                                </div>
                                                <div class="col-sm-3  multi-gd-img">
                                                    <a href="products1.html"><img src="images/woo3.jpg" alt=" " /></a>
                                                </div>
                                                <div class="col-sm-3  multi-gd-img">
                                                    <a href="products1.html"><img src="images/woo4.jpg" alt=" " /></a>
                                                </div>
                                                <div class="clearfix"></div>
                                            </div>
                                        </ul>
                                    </li>
                                    <li><a href="codes.html">Short Codes</a></li>
                                    <li><a href="mail.html">Mail Us</a></li>
                                </ul>
                            </div>
                        </nav>
                    </div>
                    @*<div class="logo-nav-right">
                            <ul class="cd-header-buttons">
                                <li><a class="cd-search-trigger" href="#cd-search"> <span></span></a></li>
                            </ul>  cd-header-buttons
                            <div id="cd-search" class="cd-search">
                                <form action="#" method="post">
                                    <input name="Search" type="search" placeholder="Search...">
                                </form>
                            </div>
                        </div>*@
                    @*<div class="header-right2">
                            <div class="cart box_1">
                                <a href="checkout.html">
                                    <h3>
                                        <div class="total">
                                            <span class="simpleCart_total"></span> (<span id="simpleCart_quantity" class="simpleCart_quantity"></span> items)
                                        </div>
                                        <img src="images/bag.png" alt="" />
                                    </h3>
                                </a>
                                <p><a href="javascript:;" class="simpleCart_empty">Empty Cart</a></p>
                                <div class="clearfix"> </div>
                            </div>
                        </div>*@
                    <div class="clearfix"> </div>
                </div>
            </div>
        </div>
    </div>
    <!--header-->
    <!--banner-->
    <div class="banner-w3">
        <div class="demo-1">
            <div id="example1" class="core-slider core-slider__carousel example_1">
                <div class="core-slider_viewport">
                    <div class="core-slider_list">
                        <div class="core-slider_item">
                            <img src="images/b1.jpg" class="img-responsive" alt="">
                        </div>
                        <div class="core-slider_item">
                            <img src="images/b2.jpg" class="img-responsive" alt="">
                        </div>
                        <div class="core-slider_item">
                            <img src="images/b3.jpg" class="img-responsive" alt="">
                        </div>
                        <div class="core-slider_item">
                            <img src="images/b4.jpg" class="img-responsive" alt="">
                        </div>
                    </div>
                </div>
                <div class="core-slider_nav">
                    <div class="core-slider_arrow core-slider_arrow__right"></div>
                    <div class="core-slider_arrow core-slider_arrow__left"></div>
                </div>
                <div class="core-slider_control-nav"></div>
            </div>
        </div>
        <link href="css/coreSlider.css" rel="stylesheet" type="text/css">
        <script src="js/coreSlider.js"></script>
        <script>
            $('#example1').coreSlider({
                pauseOnHover: false,
                interval: 3000,
                controlNavEnabled: true
            });

        </script>

    </div>
    <!--banner-->
    <!--content-->
    <div class="content">
        <!--banner-bottom-->
        <div class="ban-bottom-w3l">
            <div class="container">
                <div class="col-md-6 ban-bottom">
                    <div class="ban-top">
                        <img src="images/p1.jpg" class="img-responsive" alt="" />
                        <div class="ban-text">
                            <h4>Men’s Clothing</h4>
                        </div>
                        <div class="ban-text2 hvr-sweep-to-top">
                            <h4>50% <span>Off/-</span></h4>
                        </div>
                    </div>
                </div>
                <div class="col-md-6 ban-bottom3">
                    <div class="ban-top">
                        <img src="images/p2.jpg" class="img-responsive" alt="" />
                        <div class="ban-text1">
                            <h4>Women's Clothing</h4>
                        </div>
                    </div>
                    <div class="ban-img">
                        <div class=" ban-bottom1">
                            <div class="ban-top">
                                <img src="images/p3.jpg" class="img-responsive" alt="" />
                                <div class="ban-text1">
                                    <h4>T - Shirt</h4>
                                </div>
                            </div>
                        </div>
                        <div class="ban-bottom2">
                            <div class="ban-top">
                                <img src="images/p4.jpg" class="img-responsive" alt="" />
                                <div class="ban-text1">
                                    <h4>Hand Bag</h4>
                                </div>
                            </div>
                        </div>
                        <div class="clearfix"></div>
                    </div>
                </div>
                <div class="clearfix"></div>
            </div>
        </div>
        <!--banner-bottom-->
        <!--new-arrivals-->
        <div class="new-arrivals-w3agile">
            <div class="container">
                <h2 class="tittle">New Arrivals</h2>
                <div class="arrivals-grids">
                    @foreach (var item in Model.ShopProducts)
                    {

                        <div class="col-md-3 arrival-grid simpleCart_shelfItem" style="padding-bottom:1em;" 
                             price="@item.Price" id="@item.ID" name="@item.ProductName" profilepicture="@item.ProfilePicture">
                            <div class="grid-arr">
                                <div class="grid-arrival">
                                    <figure>
                                        <a href="#" class="new-gri" data-toggle="modal" data-target="#myModal1">
                                            <div class="grid-img">
                                                <img src="~/ProductPictures/@item.ProfilePicture" class="img-responsive" alt="">
                                            </div>
                                            <div class="grid-img">
                                                <img src="~/ProductPictures/@item.ProfilePicture" class="img-responsive" alt="">
                                            </div>
                                        </a>
                                    </figure>
                                </div>
                                @*<div class="ribben">
                                    <p>NEW</p>
                                </div>
                                <div class="ribben1">
                                    <p>SALE</p>
                                </div>*@
                                <div class="block">
                                    <div class="starbox small ghosting"> </div>
                                </div>
                                <div class="women">
                                    <h6><a href="single.html">@item.ProductName</a></h6>
                                    <span class="size">XL / XXL / S </span>
                                    <p>@*<del>$100.00</del>*@<em class="item_price">$@item.Price</em></p>
                                    <a href="#" data-text="Add To Cart" class="my-cart-b item_add">Add To Cart</a>
                                </div>
                            </div>
                        </div>

                    }
                    <div class="clearfix"></div>
                </div>
            </div>
        </div>

我确信它一定是我用于页面的模型的一个问题,因为它驻留在Web应用程序项目中但引用了类库中的模型,所以我认为这是另一个问题图书馆或参考。但问题是我无法弄清楚如何在Azure中调试以查看由于500错误导致的实际问题。这是ViewModel,Model和Controller:

视图模型:

using System;
using System.Collections.Generic;
using System.Text;

namespace LNCLibrary.Models.HomeViewModel
{
    public class HomeViewModel
    {
        public ICollection<Product> ShopProducts { get; set; }
    }
}

型号:

using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Text;

namespace LNCLibrary.Models
{
    public enum Category
    {
        Shirts,
        Accesories,

    }
    public enum Gender
    {
        Men,
        Women,
        Both

    } 

    public class Product
    {
        public int ID { get; set; }
        [Display(Name ="Name")]
        public string ProductName { get; set; }
        public int Price { get; set; }
        [Display(Name = "Gender")]
        public Gender GenderOption { get; set; }
        public int Quantity { get; set; }
        public Category Category { get; set; }
        [Display(Name ="Created")]
        public DateTime DateCreated { get; set; }
        [Display(Name = "Description")]
        public string ProductDescription { get; set; }
        public ICollection<Size> AvailableSizes { get; set; }
        [Display(Name = "Profile Picture")]
        public string ProfilePicture { get; set; }
    }
}

控制器:

 private readonly ApplicationDbContext _context;

    public HomeController(ApplicationDbContext context)
    {
        _context = context;
    }
    public async Task<IActionResult> Index()
    {
        HomeViewModel HVM = new HomeViewModel();
        HVM.ShopProducts = await _context.Products.ToListAsync();
        return View(HVM);
    }

有什么想法吗?我很难过。

2 个答案:

答案 0 :(得分:0)

使用VS中的“发布”对话框将Azure App Service废除后,打开Server Explorer(“视图”>“ Server Explorer”),右键单击App Service实例,然后选择“附加调试器”。 在正在运行的ASP.NET应用程序中,重现该错误或在此之前设置断点。 断点应在Visual Studio中命中。 喜欢本地!

答案 1 :(得分:0)

starup.cs中有一种方法Configure。启用app.UseDeveloperExceptionPage()app.UseDatabaseErrorPage()可以详细查看错误。

 public void Configure(IApplicationBuilder app, IHostingEnvironment env)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
                app.UseDatabaseErrorPage();
            }
            else
            {
                //app.UseExceptionHandler("/Home/Error");

                app.UseDeveloperExceptionPage(); // add this to see error
                app.UseDatabaseErrorPage();    // add this to see  error 

            }


        }