Home » c# » c# – ASP.NET MVC app works in debug but not when published using Plesk and GoDaddy-Exceptionshub

c# – ASP.NET MVC app works in debug but not when published using Plesk and GoDaddy-Exceptionshub

Posted by: admin February 24, 2020 Leave a comment

Questions:

I have an MVC app that works perfectly in debug mode and testing, but after I publish using ftp to godaddy, the website opens up and works when toggling between the home page and the login page. If I try logging in I get an error or if I try using the search box on my homepage, I also get an error. Here is the screenshot: Error

After I log in or basically anything or than 'mydomain'.com/Home/Index/ I get this error, if I try 'mydomain'.com/Home/Search or 'mydomain'.com/Search/Index any other controller or action I get this. What could be the cause because I have tried everything? For example is HomeController/Search:

public ActionResult Search(string search, string searchlast)
    {
        var doctors = from d in db.Doctors
                      select d;
        if (!String.IsNullOrEmpty(search) || !String.IsNullOrEmpty(searchlast))
        {
            doctors = doctors.Where(d => d.FirstName.Contains(search) && d.LastName.Contains(searchlast));
            return View(doctors.ToList());
        }
        return RedirectToAction("Index", "Home");
    }

Here is Views/Home/Search which gives the error:

@model IEnumerable<Systemz.Models.Check>
@{
    ViewBag.Title = "Search";
}

<div class="jumbotron">
    <h2>Check</h2>
    <h4>Check for availability.</h4>
</div>

@using (Html.BeginForm("Search", "Home", FormMethod.Post))
{
    <p>
        First Name: @Html.TextBox("search") Last Name: @Html.TextBox("searchlast")
        <input type="submit" value="Search" name="search" />
        <a asp-action="Search" asp-controller="Home"></a>
    </p>
}

<table class="table table-hover dataTable">
    <div class="row">
        <div class="col-md-4">
            <thead class="bd-dark white-text">
                <tr>
                    <th>
                        Title:
                    </th>
                    <th>
                        First Name:
                    </th>
                    <th>
                        Last Name:
                    </th>
                    <th>
                        Address:
                    </th>
                    <th>
                        Is Available?
                    </th>
                </tr>
            </thead>
            <tbody>
                @foreach (var item in Model)
                {
                    <tr>
                        <td>
                            @Html.DisplayFor(modelItem => item.Title)
                        </td>
                        <td>
                            @Html.DisplayFor(modelItem => item.FirstName)
                        </td>
                        <td>
                            @Html.DisplayFor(modelItem => item.LastName)
                        </td>
                        <td>
                            @Html.DisplayFor(modelItem => item.Address)
                        </td>
                        <td>
                            @if (item.IsAvailable == true)
                            {<p><a class="btn btn-success"></a></p> }
                            else
                            { <p><a class="btn btn-danger"></a></p>}
                        </td>
                    </tr>
                }
            </tbody>
        </div>
    </div>
</table>
How to&Answers:

You have to upload your database. There is no such thing as (LocalDb) on your Godaddy hosted server. You have to upload your database to Godaddy as well, figure out the connection string to that location, and then have that deploy correctly with your site. If there isn’t any firewalls in front of it, you can even test the connection to that database from your local machine.

Edit: And it isn’t enough to just upload your database file. You have to setup the database through their own tool so it attaches correctly and all that.