Vibrant discussion about CSLA .NET and using the framework to build great business applications.
Hey James
I'm attaching the principal/identity that I had when I first put together this code and should be representative of an identity/principal that works with this approach.
If you are having specific difficulties, please elaborate - information on where the process is breaking down is useful in giving you information you might be able to leverage.
Good luck,
Chris
I'm afraid I don't have a whole lot of time to look at your code right now. The message you have (the exception) is I'm pretty sure a common one that you might want to do a little searching on the forums for.
This one seemed to mention it in conjunction with WCF:
http://forums.lhotka.net/forums/post/14931.aspx
The way I was doing the authentication at the time of my posted code (it's gotten a little more robust for multiple client handling) but still works fine is in the login control's authenticate event (could be done wherever of course):
e.Authenticated = ProPrincipal.LogOn(Login1.UserName, Login1.Password);
HttpContext.Current.Session["CslaPrincipal"] = Csla.ApplicationContext.User;
That is, authenticate the user using the principal's logon, and then store the principal in a session variable for future requests - reestablishing it on future requests from the session variable.
I wish I had more time to assist you right now but I'm afraid I don't -- I can assure you that we haven't had any problems running with this code so as far as I'm concerned this is still entirely a viable approach and represents our approach. Do a little searching on the forums and see if that helps you out.
Also, I'm assuming running locally you don't have a problem but it's with remoting when it starts flaking out? There was a post on the forum where someone had the casing of CSLA wrong in the config file of the remoting server and that was causing the same exception you listed...
Hey there -
Is it when you initialize the wrapped provider that you get the error? Which line exactly are you bombing out on?
If you're talking about when Activator.CreateInstance is run and then cast, try breaking it into two lines such as:
object instance = Activator.CreateInstance(functionalProviderType); // Verify creation _wrappedProvider = (RoleProvider)instance;
Please give a bit more detail if this isn't where it's bombing out.
ok that was the exact line that was bombing out. So i've taken your advice and seperated the Activator.CreateInstance from the conversion. That line is the exact line where it's bombing out. The instance has values of Name="Nothing", ApplicationName="Nothing" and Description="Nothing". I know I've supply these values in the web.config with their proper values. So why would it be bombing out at this point? How can this be corrected?
It's OK if the instance doesn't have values, because those will get supplied when this line is invoked:
_wrappedProvider.Initialize(name, config);
It's still unclear to me which line was exactly bombing out. It created the instance of SqlRoleProvider OK (when breaking out the lines so that the only thing one line does is create an instance of SqlRoleProvider? Or did Activator.CreateInstance fail?
If Activator.CreateInstance failed, did you have a value for functionalProviderType that was established from Type.GetType()?
It's a little tricky to diagnose w/ the information given so far, but I'm trying!
Ok it bombs out right after the Initialize method and the next step that its going to is the Property Name, which has a return value of Nothing. So I'm guessing this whole problem is in the Initialize Method that isnt' fulfilling everything. This is my code, which isn't anything different from some of the samples or anything in this thread.
To answer your questions if the _functionProviderType has values, yes it does. It has the Name="SqlRoleProvider" and the FullName="System.Web.Security.SqlRoleProvider......".
#Region
_wrappedprovider.ApplicationName = value
#End
config.Remove(
_wrappedprovider =
_wrappedprovider.Initialize(name, config)
End Class
So the line that it's bombing out on is this one, right?
_wrappedprovider.Initialize(name, config);
If _wrappedprovider does get created as a SqlRoleProvider, the implementation for Initialize is below (via Reflector).
Is your ArgumentNullException's argument "config"? If so, you may be passing in an empty config array (look at the code below for SqlRoleProvider). Mine has 3 values for applicationName, connectionStringName, and description respectively.
public override void Initialize(string name, NameValueCollection config) { HttpRuntime.CheckAspNetHostingPermission(AspNetHostingPermissionLevel.Low, "Feature_not_supported_at_this_level"); if (config == null) { throw new ArgumentNullException("config"); } if (string.IsNullOrEmpty(name)) { name = "SqlRoleProvider"; } if (string.IsNullOrEmpty(config["description"])) { config.Remove("description"); config.Add("description", SR.GetString("RoleSqlProvider_description")); } base.Initialize(name, config); this._SchemaVersionCheck = 0; this._CommandTimeout = SecUtility.GetIntValue(config, "commandTimeout", 30, true, 0); string specifiedConnectionString = config["connectionStringName"]; if ((specifiedConnectionString == null) || (specifiedConnectionString.Length < 1)) { throw new ProviderException(SR.GetString("Connection_name_not_specified")); } this._sqlConnectionString = SqlConnectionHelper.GetConnectionString(specifiedConnectionString, true, true); if ((this._sqlConnectionString == null) || (this._sqlConnectionString.Length < 1)) { throw new ProviderException(SR.GetString("Connection_string_not_found", new object[] { specifiedConnectionString })); } this._AppName = config["applicationName"]; if (string.IsNullOrEmpty(this._AppName)) { this._AppName = SecUtility.GetDefaultAppName(); } if (this._AppName.Length > 0x100) { throw new ProviderException(SR.GetString("Provider_application_name_too_long")); } config.Remove("connectionStringName"); config.Remove("applicationName"); config.Remove("commandTimeout"); if (config.Count > 0) { string key = config.GetKey(0); if (!string.IsNullOrEmpty(key)) { throw new ProviderException(SR.GetString("Provider_unrecognized_attribute", new object[] { key })); } } }
Are you using the Microsoft.Samples. Because I am not. Is it better to be using them?
Not using Microsoft.Samples code, nope. I just grabbed the code for System.Web.Security.SqlRoleProvider using reflector.
Alright well anyways... The check for the config being nothing is passed and that thrown exception for the ArgumentNullException isn't being thrown at that point. It's being thrown after the Initialization Method when the Property for the Name is completed.