Спасибо за помощь, ребята - это стало критическим уроком в ведении журнала.
Я изменил код для получения категорий, чтобы просто создать предварительно заполненный список SelectList вместо его извлечения из БД.
@{
var Categories = new List<Category>(){
//new Category
//{
// CategoryId = 1,
// ParentId = 0,
// Name = "All",
// ParentCategory = null
//},
new Category
{
CategoryId = 2,
ParentId = 0,
Name = "Electronics",
ParentCategory = null
},
new Category
{
CategoryId = 3,
ParentId = 0,
Name = "Furniture",
ParentCategory = null
},
new Category
{
CategoryId = 4,
ParentId = 0,
Name = "Clothing",
ParentCategory = null
},
new Category
{
CategoryId = 5,
ParentId = 0,
Name = "Shoes",
ParentCategory = null
},
new Category
{
CategoryId = 6,
ParentId = 0,
Name = "Video Games",
ParentCategory = null
},
new Category
{
CategoryId = 7,
ParentId = 0,
Name = "Books",
ParentCategory = null
},
new Category
{
CategoryId = 8,
ParentId = 0,
Name = "Tools",
ParentCategory = null
},
new Category
{
CategoryId = 9,
ParentId = 0,
Name = "Vehicles",
ParentCategory = null
},
new Category
{
CategoryId = 10,
ParentId = 0,
Name = "Free",
ParentCategory = null
},
new Category
{
CategoryId = 11,
ParentId = 0,
Name = "Jewelry",
ParentCategory = null
},
new Category
{
CategoryId = 12,
ParentId = 0,
Name = "Crafts",
ParentCategory = null
},
new Category
{
CategoryId = 13,
ParentId = 0,
Name = "Crafts",
ParentCategory = null
},
new Category
{
CategoryId = 14,
ParentId = 0,
Name = "Appliances",
ParentCategory = null
},
new Category
{
CategoryId = 15,
ParentId = 0,
Name = "Health",
ParentCategory = null
},
new Category
{
CategoryId = 16,
ParentId = 0,
Name = "Tickets",
ParentCategory = null
},
new Category
{
CategoryId = 17,
ParentId = 0,
Name = "Services",
ParentCategory = null
},
new Category
{
CategoryId = 18,
ParentId = 0,
Name = "Home & Garden",
ParentCategory = null
},
new Category
{
CategoryId = 19,
ParentId = 0,
Name = "Collectibles",
ParentCategory = null
}
};
Но ошибка все еще создавалась - поэтому я проверил журналы после добавления NLog:
2019-05-06 12:09:56.6564|ERROR|Market.Controllers.HomeController|MaxMind.GeoIP2.Exceptions.AddressNotFoundException: The address ::1 is not in the database.
at MaxMind.GeoIP2.DatabaseReader.Execute[T](String ipStr, IPAddress ipAddress, String type, Boolean throwOnNullResponse)
at MaxMind.GeoIP2.DatabaseReader.City(IPAddress ipAddress)
at Market.Controllers.HomeController.GetGeoProducts(Nullable`1 Distance, String productSearch, String Zip, String Category) in C:\Users\nvn\source\repos\market\Market.Core\Market.Core\Controllers\HomeController.cs:line 169
at Market.Controllers.HomeController.Index(String Category, Nullable`1 Distance, String productSearch, String Zip, String sortOrder, String currentFilter, Nullable`1 pageNumber) in C:\Users\nvn\source\repos\market\Market.Core\Market.Core\Controllers\HomeController.cs:line 85
2019-05-06 12:12:07.8714|ERROR|Market.Controllers.HomeController|MaxMind.GeoIP2.Exceptions.AddressNotFoundException: The address ::1 is not in the database.
at MaxMind.GeoIP2.DatabaseReader.Execute[T](String ipStr, IPAddress ipAddress, String type, Boolean throwOnNullResponse)
at MaxMind.GeoIP2.DatabaseReader.City(IPAddress ipAddress)
at Market.Controllers.HomeController.GetGeoProducts(Nullable`1 Distance, String productSearch, String Zip, String Category) in C:\Users\nvn\source\repos\market\Market.Core\Market.Core\Controllers\HomeController.cs:line 169
at Market.Controllers.HomeController.Index(String Category, Nullable`1 Distance, String productSearch, String Zip, String sortOrder, String currentFilter, Nullable`1 pageNumber) in C:\Users\nvn\source\repos\market\Market.Core\Market.Core\Controllers\HomeController.cs:line 85
2019-05-06 12:21:50.0824|ERROR|Market.Controllers.HomeController|MaxMind.GeoIP2.Exceptions.AddressNotFoundException: The address ::1 is not in the database.
at MaxMind.GeoIP2.DatabaseReader.Execute[T](String ipStr, IPAddress ipAddress, String type, Boolean throwOnNullResponse)
at MaxMind.GeoIP2.DatabaseReader.City(IPAddress ipAddress)
at Market.Controllers.HomeController.GetGeoProducts(Nullable`1 Distance, String productSearch, String Zip, String Category) in C:\Users\nvn\source\repos\market\Market.Core\Market.Core\Controllers\HomeController.cs:line 169
at Market.Controllers.HomeController.Index(String Category, Nullable`1 Distance, String productSearch, String Zip, String sortOrder, String currentFilter, Nullable`1 pageNumber) in C:\Users\nvn\source\repos\market\Market.Core\Market.Core\Controllers\HomeController.cs:line 85
По какой-то причине фактическая ошибка - IP-адрес не найден в БД GeoIP - была скрыта в трассировке стека, которая была брошена в prod. Не совсем понятно почему, но либо использовались люди с диапазоном IP-адресов, которого у нас не было в бесплатной версии, либо возникла какая-то ошибка обратной связи, такая же, как при отладке в режиме dev.
Во всяком случае, вот как я справился с этим -
// Determine IP address of request.
var ipAddress = HttpContext.Connection.RemoteIpAddress;
try
{
// Grab the city if it's not null
var city = reader.City(ipAddress);
ViewBag.Zip = city.Postal.Code;
ViewBag.CurrentDistance = Distance;
}
catch(AddressNotFoundException e)
{
logger.Warn(e.ToString());
// Grab the city if it's not null
var city = reader.City("insert a random IP here");
ViewBag.Zip = city.Postal.Code;
ViewBag.CurrentDistance = Distance;
}
Спасибо за вашу помощь всем.