我們已經實現了對Active Directory進行身份驗證並使用System.DirectoryServices的成員資格提供程序。 在帶有webdev服務器的Visual Studio 2010上的ASP.Net MVC 3應用程序中使用此成員資格提供程序時,我們有時(6次中有1次)在登錄應用程序時遇到異常。嘗試訪問使用System.DirectoryServices時卸載的應用程序域
System.IO.FileNotFoundException: Could not load file or assembly 'System.Web' or one of its dependencies. The system cannot find the file specified.
File name: 'System.Web'
at System.Reflection.RuntimeAssembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks)
at System.Reflection.RuntimeAssembly.nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks)
at System.Reflection.RuntimeAssembly.LoadWithPartialNameInternal(AssemblyName an, Evidence securityEvidence, StackCrawlMark& stackMark)
at System.DirectoryServices.AccountManagement.UnsafeNativeMethods.IADsPathname.Retrieve(Int32 lnFormatType)
at System.DirectoryServices.AccountManagement.ADStoreCtx.LoadDomainInfo()
at System.DirectoryServices.AccountManagement.ADStoreCtx.get_DnsDomainName()
at System.DirectoryServices.AccountManagement.ADStoreCtx.GetGroupsMemberOfAZ(Principal p)
at System.DirectoryServices.AccountManagement.UserPrincipal.GetAuthorizationGroupsHelper()
at System.DirectoryServices.AccountManagement.UserPrincipal.GetAuthorizationGroups()
=== Pre-bind state information ===
LOG: DisplayName = System.Web (Partial)
WRN: Partial binding information was supplied for an assembly:
WRN: Assembly Name: System.Web | Domain ID: 2
WRN: A partial bind occurs when only part of the assembly display name is provided.
WRN: This might result in the binder loading an incorrect assembly.
WRN: It is recommended to provide a fully specified textual identity for the assembly,
WRN: that consists of the simple name, version, culture, and public key token.
WRN: See whitepaper http://go.microsoft.com/fwlink/?LinkId=109270 for more information and common solutions to this issue.
Calling assembly : HibernatingRhinos.Profiler.Appender, Version=1.0.0.0, Culture=neutral, PublicKeyToken=0774796e73ebf640.
調用程序集是HibernatingRhinos.Profiler.Appender所以log4net的配置禁用探查後,我們到了真正的例外:
System.AppDomainUnloadedException: Attempted to access an unloaded appdomain. (Except at System.StubHelpers.StubHelpers.InternalGetCOMHRExceptionObject(Int32 hr, IntPtr pCPCMD, Object pThis)
at System.StubHelpers.StubHelpers.GetCOMHRExceptionObject(Int32 hr, IntPtr pCPCMD, Object pThis)
at System.DirectoryServices.AccountManagement.UnsafeNativeMethods.IADsPathname.Retrieve(Int32 lnFormatType)
at System.DirectoryServices.AccountManagement.ADStoreCtx.LoadDomainInfo()
at System.DirectoryServices.AccountManagement.ADStoreCtx.get_DnsDomainName()
at System.DirectoryServices.AccountManagement.ADStoreCtx.GetGroupsMemberOfAZ(Principal p)
at System.DirectoryServices.AccountManagement.UserPrincipal.GetAuthorizationGroupsHelper()
at System.DirectoryServices.AccountManagement.UserPrincipal.GetAuthorizationGroups()
異常總是以同樣的方法拋出,但對於現在我們無法隨機地重現它,但大約6次中有1次。 但是,當使用IIs代替內置的Visual Studio 2010 Web服務器時,我們並沒有得到例外。
當在Visual Studio webdev的上下文中使用多個appdomains時,它可能與賽車條件有關,但這只是猜測。 我們真的很想知道問題的原因是什麼,因爲我們不希望在生產環境中出現這些異常情況。
我們發現2類似的情況,但都沒有找到真正的解決辦法:
http://forums.asp.net/t/1556949.aspx/1
更新18-05-2011
的代碼量最小(在asp.net mvc)重現異常,其中userName是您的Active Directory登錄名。
using System.DirectoryServices.AccountManagement;
using System.Web.Mvc;
namespace ADBug.Controllers
{
public class HomeController : Controller
{
public ActionResult Index()
{
string userName = "nickvane";
var principalContext = new PrincipalContext(ContextType.Domain);
UserPrincipal userPrincipal = UserPrincipal.FindByIdentity(
principalContext,
IdentityType.SamAccountName,
userName);
if (userPrincipal != null)
{
PrincipalSearchResult<Principal> list = userPrincipal.GetAuthorizationGroups();
}
return View();
}
}
}
唉,異常仍然是隨機發生的,所以沒有完全可重現的錯誤。
的問題也被提交給微軟:[http://connect.microsoft.com/VisualStudio/feedback/details/566463 /試圖訪問一個卸載應用程序域異常從hresult-0x80131014 - 當調用getauthorizationgroups] – nickvane 2011-05-05 09:04:48
我遇到同樣的問題,當使用ActiveDirectoryMembershipProvider。對我來說,當我第一次調用Membership.ValidateUser()時它正在發生,它正在嘗試創建提供程序。 – 2012-01-12 13:12:57