MVC中很奇怪的问题

情况是这样的, 慢慢听我道来~

新建了一个MVC 3的项目, 在HomeController中继承BaseController

1 using System;
2  using System.Collections.Generic;
3  using System.Linq;
4  using System.Web;
5  using System.Web.Mvc;
6  using System.Web.UI;
7
8  using Cloud.Config;
9
10  namespace UserCenter.Controllers
11 {
12 public class HomeController : BaseController
13 {
14 public HomeController()
15 {
16 }
17
18 //
19 // GET: /Home/
20  
21 public ActionResult Index()
22 {
23 return View();
24 }
25
26 }
27 }

BaseController代码如下

using System;
 using System.Collections.Generic;
 using System.Linq;
 using System.Web;
 using System.Web.Mvc;
 using System.Web.UI;
 using Cloud.Config;

 namespace UserCenter.Controllers
{
/// <summary>
/// 基础
/// </summary>
  public class BaseController : Controller
{
public BaseController()
{
if(Cookie("login") == null)
{
          // 这地方报错, 未将对象引用设置到对象的实例。
Response.Redirect(Url.Action("Login", "Account"));

          // 这地方不报错
          System.Web.HttpContext.Current.Response.Redirect(Url.Action("Login", "Account"));
}
}
  }
}

命名里的为啥就要补全? 简写语法不报错, 但是执行的时候就报错了

我已经引用了, 如果没引用报错我认了, 但这问题真的很崩溃

原文地址:https://www.cnblogs.com/yangyunzhou/p/1949601.html