我的MVC应用程序的一部分在实时部署时无法工作
本文关键字:部署 工作 实时 MVC 应用程序 一部分 我的 | 更新日期: 2023-09-27 18:28:19
这是我第一次在AmazonS3服务器中部署MVC web应用程序。网站已经在浏览器中加载,但当我点击注册按钮时,它会抛出错误。我能看到唯一的区别是我的应用程序名为reporting.e-tale.co.uk,域设置为dashboard.e-tale.co.uk,所以我在live中创建了一个文件夹,名为dashbard.e-taleco.uk并复制了我的文件。它在本地运行良好,不知道它抛出错误的原因。
如果我做错了什么,请纠正我。我不知道该提供什么细节。如果很难提出解决方案,我将向您提供更多细节。感谢
"/"应用程序中的服务器错误。
对象引用未设置为对象的实例。
描述:在执行当前web请求期间发生未处理的异常。请查看堆栈跟踪以了解有关错误以及错误在代码中的来源的更多信息。
异常详细信息:System.NullReferenceException:对象引用未设置为对象的实例。
来源错误:
在执行当前web请求期间生成了未处理的异常。可以使用下面的异常堆栈跟踪来识别有关异常的起源和位置的信息。
堆栈跟踪:
[NullReferenceException:对象引用未设置为对象的实例。]reporting.e_tale.co.uk.Controllers.AccountController.Register()+255lambda_method(闭包,ControllerBase,Object[])+78System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext ControllerContext,IDictionary 2 parameters) +263
System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary
2参数)+38System.Web.Mvc.<>c_显示类15.b_12()+128System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter filter,ActionExecutingContext preContext,Func 1 continuation) +826106
System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter filter, ActionExecutingContext preContext, Func
1 continuation)+826106System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter筛选器、ActionExecutingContext preContext、Func 1 continuation) +826106
System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodWithFilters(ControllerContext controllerContext, IList
1筛选器、ActionDescriptor ActionDescriptor、IDictionary `2参数)+314System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext ControllerContext,String actionName)+825228System.Web.Mvc.Controller.ExecuteCore()+159System.Web.Mvc.ControllerBase.Execute(RequestContext RequestContext)+335System.Web.Mvc.<>c_显示类b.b_5()+62System.Web.Mvc.Async。<>c_DisplayClass1.b_0()+20System.Web.Mvc.<>c_显示类.b_d()+54System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()+469System.Web.HttpApplication.ExecuteStep(IExecutionStep步骤,Boolean和completedSynchronously)+375
版本信息:Microsoft.NET Framework版本:4.0.30319;ASP.NET版本:4.0.30319.1008
账户管理员(注册)
/// <summary>
/// GET: /Account/Register
/// Action account Register.
/// </summary>
/// <returns></returns>
[AcceptVerbs(HttpVerbs.Get)]
public ActionResult Register()
{
var myViewData = new RegisterForm
{
Person = new Person
{
CreatedAt = DateTime.Now,
AppellationId =
_appellationRepository.GetAppellationByDescription(
"Mr").Id,
CountryId =
_countryRepository.GetCountryByName(
"United Kingdom").Id,
CorporationId = _corporationRepository.GetCorporationByName(
"Samsung").Id
//ManufacturerId = _manufacturerRepository.GetManufacturerByName(
//"Samsung").Id
},
User =
new User
{
CreatedAt = DateTime.Now,
Guid = Guid.NewGuid().ToString("N")
}
};
myViewData.Appellations = new SelectList(_appellationRepository.GetAllAppellations().ToList(), "Id",
"Description", myViewData.Person.AppellationId);
myViewData.Countries = new SelectList(_countryRepository.GetAllCountries().ToList(), "Id", "Name",
myViewData.Person.CountryId);
myViewData.Corporations = new SelectList(_corporationRepository.GetAllcorporations().ToList(), "Id",
"Description", myViewData.Person.CorporationId);
//myViewData.Manufacturers = new SelectList(_manufacturerRepository.GetAllManufacturers().ToList(),"Id",
// "Description",myViewData.Person.ManufacturerId);
myViewData.PasswordLength = MembershipService.MinPasswordLength;
return View(myViewData);
}
您的代码不是很具有防御性。。因此你的问题。
在AccountController
的Register()
方法中有一个null
对象。。那可能是什么?
其中任何一个:
_appellationRepository.GetAppellationByDescription("Mr")
_countryRepository.GetCountryByName("United Kingdom")
_corporationRepository.GetCorporationByName("Samsung")
检查您的数据,并检查您的存储库是否实际返回了数据。您不能检查null
对象的属性(通过在上述每个调用之后都有.Id
来执行此操作)。正如我在评论中所说的。。这可能是因为您的实时数据库没有包含本地数据库包含的所有数据。确保他们1比1匹配,当你在那里的时候。。。设置一些防御机制!例如:
var country = _countryRepository.GetCountryByName("United Kingdom");
if (country == null)
// Log the error or give a more descriptive error