My colleague has been working on a web part in an FBA environment. Among other things, the web part pulls some data from SQL server. The grand plan for this project dictates that a DBA configures data level security in SQL (ut opponitur ad a user embedding ID SQL query in a, aut alio aditu).
The problem is that SQL server doesn’t know anything about our FBA environment so it can’t trust us. We solved this problem by, pro defectu melius verbum, manually impersonating an AD user so that we could connect to SQL such that SQL data level security works.
Est ASP.NET quamvis FBA pluma, nos docuerunt populum SharePoint Gente diversis quaero engines quod es querying pro FBA, you must mean you want know how to configure FBA in SharePoint. I failed to find find any information on how to enable an FBA oriented ASP.NET application to communicate with SQL in the way we needed.
In hoc tractu investigantibus, nos re-lego is article: ASP.NET imitatione discretos
Magis investigationis duxit nos ad hoc articulus codproject: http://www.codeproject.com/KB/cs/cpimpersonation1.aspx
Quod nostris moribus auxiliatus est nobis scribere, which I’ve included below. It’s not the most elegant stuff, but it worked. I hope you find it helpful.
Hic 'quod operatus est in nobis codicem:
protegetur btnSearchCarrier_Click vacuo(obiectum mittentis, E EventArgs) { experiri { ImpersonateUser iu- novum ImpersonateUser(); // Todo: Restituo credentials ("DomainName", "UserName", "Password"); // LEX // iU.Undo(); } capiendos (Exceptio ex) { } } // Sicut infra annotatum genere utens imitatione discretos. publica genus ImpersonateUser { [DllImport("advapi32.dll", SetLastError = verum)] publica static externus bool LogonUser( String lpszUsername, String lpszDomain, String lpszPassword, int dwLogonType, int dwLogonProvider, Ref IntPtr phToken); [DllImport("kernel32.dll", Charset = CharSet.Auto)] privatis externus static bool CloseHandle(IntPtr manubrio); privatis static IntPtr tokenHandle = novum IntPtr(0); privatis static WindowsImpersonationContext impersonatedUser; // Si in hoc Codice incorporamus DLL, esse certa ad eam deposcendam // decurrat FullTrust. [PermissionSetAttribute(SecurityAction.Demand, Name = "FullTrust")] publica Irrita Personatus(string domainName, string username, string Signum) { experiri { // Utor user indicium pro unmanaged LogonUser muneris impetro // User praefinitum, dominico, et password. Const int LOGON32_PROVIDER_DEFAULT = 0; // Praeteriens hoc parameter facit LogonUser creare primum indicium. Const int LOGON32_LOGON_INTERACTIVE = 2; tokenHandle = IntPtr.Zero; // Ingrediamur -1 Vocare ad obtinere LogonUser manubrium accessum indicium. bool returnValue = LogonUser( Username, domainName, Signum, LOGON32_LOGON_INTERACTIVE, LOGON32_PROVIDER_DEFAULT, Ref tokenHandle); // tokenHandle - novum securitatis indicium si (returnValue falsum ==) { int-ret Marshal.GetLastWin32Error(); Console.WriteLine("LogonUser call failed with error code : " + ret); mittent novum System.ComponentModel.Win32Exception(ret); } // Ingrediamur - 2 WindowsIdentity newId = novum WindowsIdentity(tokenHandle); // Ingrediamur -3 impersonatedUser = newId.Impersonate(); } capiendos (Exceptio ex) { Console.WriteLine("Exception occurred. " + ex.Message); } } /// <Summary> /// Sistit imitatione discretos /// </Summary> publica Irrita abrogare() { impersonatedUser.Undo(); // Libera indicia. si (tokenHandle != IntPtr.Zero) CloseHandle(tokenHandle); } }
</finem>