我有一个非常愚蠢的问题,但无论如何我都会有.
这是我的控制器中用于登录的代码
[HttpPost]
public ActionResult Index(LogonModel model, string ReturnUrl)
{
ReturnUrl = Request.QueryString["ReturnUrl"];
if (ModelState.IsValid)
{
if (UserRepository.validLogin(model.Username, model.Password))
{
UserLogRepository.createLogEntry("Log On", " has logged on to the Staff Portal.", "Entry/Exit");
if (ReturnUrl.Length > 1)
{
return Redirect(Request.QueryString["ReturnUrl"]);
}
else
{
return RedirectToAction("Dashboard", "Home");
}
}
else
{
ModelState.AddModelError("", Session["Error"].ToString());
}
}
// If we got this far, something failed, redisplay form
return View(model);
}
Run Code Online (Sandbox Code Playgroud)
正如您所看到的那样,我只是在检查返回器是否具有用于测试目的的长度之后再将其锁定更多.我的问题是我得到一个"对象引用未设置为对象的实例".指向这一行"if(ReturnUrl.Length> 1)"
现在,当用户从网站超时时我所拥有的URL是: http:// localhost/Dispatch2012/Staff/Home?ReturnUrl = Dispatch2012%2FStaff%2FCredential
正如您所看到的,这是MVC 3创建的标准重定向,我尝试将ReturnUrl作为标准查询字符串读取,但每次都表示该对象不存在.我错过了什么?