locked
Asp.net Core MVC routing not working after deployment RRS feed

  • Question

  • User-162959904 posted

    I have a working ASP.net core MVC website in Visual Studio 2019 Community Edition, but when I deploy it to a remote hosting provider, some of the menu links give a 404 not found error.

    The site (http://www.dljsoftware.co.uk) is for a mountain club. There is a menu link Club/About Us. From the page source I can see the correct link of <a class="dropdown-item" href="/Club/AboutUs">About us</a>, but clicking on the menu link gives a 404 error, suggesting that the AboutUs method in the Club controller is missing or the view AboutUs is missing

    However both the method and view are present in the Visual Studio code as seen from the fact that the link works correctly in VS. I have published the code in Visual Studio and deployed it to the remote site using Web Deploy

    Has anybody any idea what could be going wrong

    David

    Wednesday, February 26, 2020 6:48 PM

Answers

  • User-162959904 posted

    Hi Sam

    I have finally resolved the issue., which was a discrepancy between my local database and the remote database. I had added a column on my local database, and not updated the remote database. The error messages were misleading, and suggested a coding error

    Thanks again for your help

    David

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, February 28, 2020 2:54 PM

All replies

  • User475983607 posted

    Is "Club" an area because this works...

    http://www.dljsoftware.co.uk/Club/Links/All


      

    Wednesday, February 26, 2020 6:59 PM
  • User-162959904 posted

    Many thanks for your very swift reply

    No Club is not an area, .Club/Joining and Club/Newsletters) work but not Club/Contacts.  There are also a couple of other broken links.

    I have a working version of the site at https://www.gwydyrmc.org.uk and after making some minor changes I posted the revised code to http://www.dljsoftware.co.uk to test them. In the working version there is a link Club/General and I changed the name of the General method and view to AboutUs with some minor change including changes to the Contacts view. However everything works in Visual Studio

    I can post the Club controller if that helps as there is nothing confidential about it

    David

    Wednesday, February 26, 2020 7:28 PM
  • User288213138 posted

    Hi DavidL-J,

    In the working version there is a link Club/General and I changed the name of the General method and view to AboutUs with some minor change including changes to the Contacts view

    I think there may be many reasons for this problem, first you should check your map route statement is correct.

    If there are no problems, please post the relevant code you modified.

    Best regards,

    Sam

    Thursday, February 27, 2020 6:18 AM
  • User-162959904 posted

    Thanks Sam

    I have tried updating to Visual Studio Community version 16.4.5 and I still have the same problem

    The code from the Startup.cs file with the map route statement is below - I had not changed this

    The Club controller code and the code for the AboutUs view (AboutUs.cshtml) are below  In pasting it I have lost the indentation, which makes it harder to read., but I cannot see anything wrong with either of them

    namespace Gwydyr
    {
    public class Startup
    {
    public Startup(IConfiguration configuration)
    {
    Configuration = configuration;
    }

    public IConfiguration Configuration { get; }

    // This method gets called by the runtime. Use this method to add services to the container.
    public void ConfigureServices(IServiceCollection services)
    {
    ........................................
    }

    // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
    public void Configure(IApplicationBuilder app, IHostingEnvironment env)
    {
    if (env.IsDevelopment())
    {
    app.UseBrowserLink();
    app.UseDeveloperExceptionPage();
    app.UseDatabaseErrorPage();
    }
    else
    {
    app.UseExceptionHandler("/Home/Error");
    }

    app.UseStaticFiles();

    app.UseAuthentication();

    app.UseMvc(routes =>
    {
    routes.MapRoute(
    name: "default",
    template: "{controller=Home}/{action=Home}/{id?}/{*more}");
    });
    }
    }
    }

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Threading.Tasks;
    using Microsoft.AspNetCore.Mvc;
    using Microsoft.AspNetCore.Hosting;
    using Microsoft.AspNetCore.Mvc.Rendering;
    using Microsoft.EntityFrameworkCore;
    using Gwydyr.Data;
    using Gwydyr.Models;
    using Microsoft.AspNetCore.Identity;
    using Microsoft.AspNetCore.Authorization;

    namespace Gwydyr.Controllers
    {
    public class ClubController : Controller
    {
    private readonly EFDbContext _context;
    private readonly IHostingEnvironment _hostingEnvironment;
    private readonly UserManager<ApplicationUser> _userManager;
    private string _contentRootPath;

    public ClubController(UserManager<ApplicationUser> userManager, EFDbContext context, IHostingEnvironment hostingEnvironment)
    {
    _userManager = userManager;
    _context = context;
    _hostingEnvironment = hostingEnvironment;
    _contentRootPath = hostingEnvironment.ContentRootPath;
    }

    public ViewResult AboutUs()
    {
    CommitteeMember memberSecretary = _context.CommitteeMembers
    .FirstOrDefault(c => c.Position == "Membership Secretary");
    if (memberSecretary != null)
    {
    ViewBag.MemberSecretary = memberSecretary.Forename + " " + memberSecretary.Surname;
    ViewBag.Forename = memberSecretary.Forename;
    }
    else
    {
    ViewBag.MemberSecretary = "Membership Secretary";
    ViewBag.Forename = "the Membership Secretary";
    }
    return View("AboutUs");
    }

    -------------------
    }
    }

    File AboutUs.cshtml

    @{
    ViewBag.Title = "About the Club";

    }


    <div class="col-12 col-md-8" style="float:left">
    <h2 class="pageHeader">Our Club</h2>


    <p>
    The Gwydyr Mountain Club is for people who like outside activities, principally in the mountains. These activities include mountain walking,
    scrambling, rock climbing both indoors and outdoors, and snow and ice climbing when available. Members also go mountain biking and coast walking.
    </p>

    <p>
    We are a Wirral based club, despite the Welsh name, but we aso have members from Liverpool and other parts of the county. Our formal Club meetings are held in Birkenhead at Gallaghers Traditional Pub (see @Html.ActionLink("map", "Gallaghers", "Club")).
    The Club owns a hut in Capel Curig (close to the Gwydyr forest) and also a self-catering cottage. Members pay an annual
    membership fee, which includes use of the club hut and discounts on bookings for our cottage as well as
    <a asp-controller="Club" asp-action="Links" asp-route-id="Discounts">discounts</a> at local outdoor shops and indoor climbing centres.
    </p>

    <p>
    A meets program is compiled annually from members’ suggestions and covers the main hill and
    <a data-fancybox data-src="#torridon" href="javascript:;">
    mountain areas
    </a>
    of the UK and Ireland.
    The program is a mixture of day, weekend and longer visits, usually using shared private transport and based on either
    self-catering (often other club's huts) accommodation or camping. There are the regular meets at Capel Curig based on the Club hut and there are sometimes trips to the
    <a data-fancybox data-src="#alps" href="javascript:;">
    Alps
    </a>
    and

    <a data-fancybox data-src="#sikkim" href="javascript:;">
    further afield
    </a>.
    </p>

    <p>
    In addition to our mountain activities, there is a strong

    <a data-fancybox data-src="#socialelement" href="javascript:;">
    social element
    </a>

    to the Club. The Club meets at Gallaghers Traditional Club from 9.00 pm every Tuesday evening, which is an
    excellent way for those interested in our activities to meet us. Our monthly club weekends at our hut in Capel Curig are also a good way to meet people with similar interests, and there is always a great atmosphere if you do not
    object to a bit of banter with your friends. Prospective female members are very welcome, as we have a good number of women members, who would be happy to reassure you that this is a good club for both sexes.
    </p>


    <p>
    If you would like further information about our Club, or are interested in joining us on one of our meets to see if this would be for you,
    please @Html.ActionLink("contact our Membership Secretary", "ProspectiveEnquiry", "Enquiry") (@ViewBag.MemberSecretary), giving some idea of your interests, and @ViewBag.Forename will be in touch with you.
    Alternatively just come down to Gallaghers any Tuesday and introduce yourself.
    </p>

    <p>For more information about the Gwydyr Mountain Club and how to join our Wirral\Liverpool based mountaineering club we have put together a @Html.ActionLink("Frequently Asked Questions", "FAQ", "Club") section (in .pdf format).</p>
    </div>

    <div style="display: none;" id="socialelement">
    <div class="row">
    <div class="col-12 col-md-8 col-lg-6 offset-md-2 offset-lg-3">
    <h2 class="pageHeader">Social events</h2>
    <p>There is a strong social element to getting out into the hills with fellow club members, and usually we end up having an "off the hill pint" (or maybe two)</p>

    <p>
    In addition we have had some great parties in the hut. The Bonfire Night party is a regular and very popular event, which is often a fancy dress event which allows members to show their imagination. The photo below is of a Halloween Party at the hut
    </p>
    </div>

    <div class="col-12 col-md-8 col-lg-6 offset-md-2 offset-lg-3">
    <img class="img-fluid" alt="Halloween"
    src="@Url.Content("~/Images/General/Halloween party.jpg")" />
    </div>
    </div>
    </div>

    <div style="display: none;" id="alps">
    <div class="row">
    <div class="col-12 col-md-8 col-lg-6 offset-md-2 offset-lg-3">
    <h2 class="pageHeader">The Alps</h2>
    <p>In September 2015 Anna organised a week's trip to Chamonix, where 16 of us stayed in a very smart skiing chalet for the astonishing low season price of £110 punds each (plus flights). </p>

    <p>
    On the final day, 5 of us tried out paragliding from the Brevent cable car station, and the photo shows us all safely down together with our pilots (we were in tandem)
    </p>
    </div>

    <div class="col-12 col-md-8 col-lg-6 offset-md-2 offset-lg-3">
    <img class="img-fluid" alt="Alps"
    src="@Url.Content("~/Images/General/Chamonix2015.jpg")" />
    </div>
    </div>
    </div>

    <div style="display: none;" id="sikkim">
    <div class="row">
    <div class="col-12 col-md-8 col-lg-6 offset-md-2 offset-lg-3">
    <h2 class="pageHeader">The Himalayas</h2>
    <p>To celebrate the club's 50th anniversary in 2017, Roger organised an expedition to Sikkim in the Indian Himalayas.</p>

    <p>
    The group photo was taken at over 4,000m on the approach towards Mt Kanchenchunga. Seven of the party then split off for an attempt to climb Mt Thinchinchang
    </p>
    </div>

    <div class="col-12 col-md-8 col-lg-6 offset-md-2 offset-lg-3">
    <img class="img-fluid" alt="Sikkim"
    src="@Url.Content("~/Images/General/Sikkim2017.jpg")" />
    </div>
    </div>
    </div>

    <div style="display: none;" id="torridon">
    <div class="row">
    <div class="col-12 col-md-8 col-lg-6 offset-md-2 offset-lg-3">
    <h2 class="pageHeader">Scotland</h2>
    <p>For the last few year's Teresa has organised a meet in Scotland at the end of May, and these meets have been very popular. We have been to Torridon, Arran, Knoydart, Ullapool, Skye</p>

    <p>
    The photo was taken in Torridon, where there are some really magnificent mountains.
    </p>
    </div>

    <div class="col-12 col-md-8 col-lg-6 offset-md-2 offset-lg-3">
    <img class="img-fluid" alt="Halloween"
    src="@Url.Content("~/Images/General/Torridon2012.jpg")" />
    </div>
    </div>
    </div>

    <div class="col-12 d-none col-lg-4 d-lg-block" style="; top: 36px; float:right; margin-right:10px; width:280px">

    <img alt="" src="@Url.Content("~/Images/Meets/StJohnsInTheVale.jpg")" style="width:250px; height:140px; margin-top:6px; margin-left:13px; margin-bottom:3px" />
    <div style="text-align:center; margin-bottom:6px">
    Walking in the Lake District
    </div>

    <img alt="" src="@Url.Content("~/Images/General/Winter skills.jpg")" style="width:250px; height:150px; margin-top:6px; margin-left:13px; margin-bottom:3px" />
    <div style="text-align:center; margin-bottom:6px">
    Winter skills course at Fort William
    </div>

    <img alt="" src="@Url.Content("~/Images/General/Symphony_crack.jpg")" style="width:250px; height:140px; margin-top:6px; margin-left:13px; margin-bottom:3px" />
    <div style="text-align:center; margin-bottom:4px">
    Rock climbing at Rhoscolyn
    </div>

    </div>

    David

    Thursday, February 27, 2020 3:54 PM
  • User288213138 posted

    Hi DavidL-J,

    I looked at your code and found nothing wrong. Where did you modify it?

    In the working version there is a link Club/General and I changed the name of the General method and view to AboutUs with some minor change including changes to the Contacts view

    And I found that you changed the name of the method and the view. Did you change the name of the view when you published it?

    Best regards,

    Sam

    Friday, February 28, 2020 6:05 AM
  • User-162959904 posted

    Thanks Sam

    The views are compiled before publishing, so I think I cannot have changed the view name before publishing.

    You have however confirmed my view that there is nothing wrong with the code. I suspect that there must be some other difference between the local setup and that on the remote server. I will continue to investigate and publish any conclusion.

    Many thanks for taking the trouble to look through all that code

    David

    Friday, February 28, 2020 9:11 AM
  • User-162959904 posted

    Hi Sam

    I have finally resolved the issue., which was a discrepancy between my local database and the remote database. I had added a column on my local database, and not updated the remote database. The error messages were misleading, and suggested a coding error

    Thanks again for your help

    David

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, February 28, 2020 2:54 PM