0
我有一個自定義的成員提供它看起來像這樣:調用自定義函數
public class PMembershipProvider : MembershipProvider
{
public IMembershipService Account { get; set; }
public PMembershipProvider()
{
this.Account = new UserModel();
}
public override bool ValidateUser(string username, string password)
{
return Account.Login(username, password);
}
public void DisposeContext()
{
Account.Dispose();
}
}
和會員服務接口,看起來像這樣:
public interface IMembershipService
{
bool Login(string userName, string password);
void Dispose();
}
因此,當我去登錄在用戶中,我可以調用我的用戶模型的登錄方法,如下所示:
public class UserController : Controller
{
public ActionResult Login(UserModel model)
{
if (Membership.ValidateUser(model.name, model.password)) {
FormsAuthentication.SetAuthCookie(model.name, false, MvcApplication.BASE_URL);
return RedirectToAction("Index", "Home");
}
}
我在運行進入一些奇怪的用戶問題,我認爲這些用戶問題與未處置的EF對象上下文相關聯。基於this answer我想嘗試手動處理由成員資格提供程序使用的對象上下文。我想這是在請求結束髮生,爲此,我要重寫我的用戶控制器的Dispose
方法:
protected override void Dispose(bool disposing)
{
base.Dispose(disposing);
Membership.DisposeContext(); //this is what I want to do, but it doesn't work
}
當我嘗試打電話給我的定義成員資格提供能夠快速」的DisposeContext
方法找到方法。 (「System.Web.Security.Membership」不包含「DisposeContext」的定義)
我怎麼能說我的DisposeContext
由會員使用相同的對象的方法?
啊...我幾乎試過了確切的事情。儘管如此,謝謝! – Mansfield