views:

133

answers:

2

Hello,


Q1 Book suggests that before we register new SqlProfileProvider, we should remove any existing profile providers using <clear> element. But:

A) why must we use <clear> instead of <remove>?

B) I assume that root web.config or machine.config don’t register (by default) any profile provider, and thus using <clear> element is not necessary?


Q2 I assume reason why each profile property doesn’t have a corresponding column in a database table ( instead all properties are stored into a single field ) is due to the fact each time we would add and remove profile properties, we would also need to change table schema?


thanx

+2  A: 

Actually, the AspNetSqlProfileProvider (of type System.Web.Profile.SqlProfileProvider) is added by default in machine.config. Take a look at your C:\Windows\Microsoft.NET\Framework\v2.0.50727\CONFIG directory (or another location). However, it is not registered as the default provider there. So if you are satisfied with the default settings, it is enough to use the following configuration:

<profile enabled="true" defaultProvider="AspNetSqlProfileProvider" />

If you want to use a custom provider, it's usually a good idea to clear all existing providers (although not necessary) and name another default provider.

The reason for not using remove is that it requires a name attribute, which you may not know. Using clear removes all previously registered profile providers, using remove removes just one by name.

Concerning Q2 you´re correct. The database scheme that is used must be general enough to accomodate lots of different properties (and types of properties).

Ronald Wildenberg
A) If there is already SqlProfileProvider provider defined in machine.config, then why I was still able to use provider I registered inside application’s root web.config, even though I didn’t use <clear>to remove the existing provider? Shouldn't that cause some kind of error?B) I assume <clear> removes all elements, while <remove> only removes a specific element? C) Perhaps a stupid question – when removing SqlMembershipProvider or SqlRoleProvider my book always used <remove>, but with SqlProfileProvider it used <clear> instead. Any particular reason for that?
SourceC
(a) If you'd given it a different name, you can add as many providers as you like, either of the same or different types. (b) Yes, that's correct. (c) No idea - which book are you using? I'd always tend to go with <clear /> as well because you know you've got them all. Perhaps the author was just showing a different way of doing it.
Zhaph - Ben Duguid
I added some more information to my answer in line with the information provided by Zhaph - Ben Duguid.
Ronald Wildenberg
In case you’ll still be reading this - I don’t want to spam with another thread, so… why if I register( in application’s root web.config file) a module, say FormsAuthanticationModule, with same name as FormsAuthenticationModule registered in root web.config, why doesn’t application report an error due to two modules having the same name? Anyways, thank you guys for helping me
SourceC
I'm not sure how modules behave in this aspect, but adding two providers with the same name gives you an error.
Ronald Wildenberg
thank you both for your kind help
SourceC
+1  A: 

Following on from RWWilden's answer, there is a SQL Table Profile Provider available, that does map properties into columns in a database:

Table Profile Provider Samples

ScottGu had a brief introduction to them here:

ASP.NET 2.0 SQL Table Profile Provider

Zhaph - Ben Duguid
great links...thanx
SourceC