2
我有多個共享成員資格數據庫的應用程序。在提交控制器,我試圖獲取用戶名:Membership.GetUser()返回NULL
var userId = (int)Membership.GetUser().ProviderUserKey;
但它總是給我的錯誤:
Object reference not set to an instance of an object.
它可以在其他應用程序就好了。我只有這個應用程序的問題。以下是我的提交控制器:
[Authorize]
[OutputCache(Duration = 0)]
[InitializeSimpleMembership]
public class SubmissionsController : Controller
{
private ProductionReportDBEntities db = new ProductionReportDBEntities();
public ActionResult Index()
{
var u = Membership.GetUser().ProviderUserKey;
...
}
}
我錯過了什麼?