Autor Beitrag
kingdave2nd
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 54



BeitragVerfasst: Mi 29.07.09 08:52 
Hi,

ich glaube ich stelle jetzt eine peinliche Frage, aber irgendwie kapier ich den ProfileProvider total nicht (Brett vorm Hirn). Ich beschreib mal wo ich grade bin und was ich vor habe:

Ich habe eine RegisterUser.aspx in der das CreateUserWizard Control eingebaut ist. Dieses Control möchte ich nun um weitere Labels erweitern und über den ProfileProvider in die Tabelle aspnet_Profiles die eingegebenen Werte als Properties speichern. Ich habe auch schon properties in der web.config definiert. Jetzt ist mir aber irgendwie total nicht klar, wie ich meine textboxen mit denen in der web.config definierten properties verknüpfen kann und diese dann in die DB speichere.

Ich bin sicher das ist alles gar nicht so schwer, aber irgendwie schleicht sich die Site mit dem passenden Anstoss an meinem google immer vorbei ;-)

Gruss Dave
kingdave2nd Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 54



BeitragVerfasst: Mi 29.07.09 09:20 
Noch ein kleiner Nachtrag:

Scott Mitchel schreibt in seinem Artikel über den Profile Provider:

Zitat:

After defining your Profile properties, the ASP.NET engine automatically creates a ProfileCommon class that has properties that map to the properties defined in Web.config (which allows for IntelliSense and compile-time type checking). This class is dynamically recreated whenever the properties defined in Web.config are modified and automatically works with the currently logged on user's profile. (You can also turn on profile support for anonymous users, and later migrate their profile data once they've logged on. But this topic is beyond the scope of this article, and will have to wait for a future installment of this series!)

The custom ProfileCommon class is accessible in the code portion of an ASP.NET page through the HttpContext object's Profile property. For example, to read the currently logged on user's HomepageUrl property from an ASP.NET page, simply use Profile.HomepageUrl


Doof nur: Ich habe nirgendswo eine ProfileCommon Class zur Verfügung. Auch im Namespace System.Web.Profile finde ich die einfach nicht wieder...

Verzweifel ...
kingdave2nd Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 54



BeitragVerfasst: Mi 29.07.09 11:15 
Ich noch mal,

mittlerweile habe ich noch ein bisschen mehr herausgefunden. In der MSDN gibt es einen WebProfile Builder. Fakt ist, das ASP.NET 2.0 WebApplication nicht mehr die dynamische Codegenerierung zulassen, über die die vermisste ProfileCommon Klasse generiert werden würde. Über dieses VS SnapIn wird dies wieder möglich gemacht (Nur dass man nun halt eine WebProfile Klasse erhält). Soweit so gut. Jetzt habe ich 2 weitere Fragen dazu:

1) Es ergibt sich nun ein weiteres technisches Problem:
Ich habe nun den Code

ausblenden C#-Quelltext
1:
2:
3:
4:
5:
        protected void CreateUserWizard_CreatedUser(object sender, EventArgs e)
        {
            WebProfile profile = WebProfile.GetProfile(CreateUserWizard.UserName);
            profile.City = CreateUserWizard.Answer;
        }


in meine register.aspx.cs Seite eingefügt (In der register.aspx steckt auch mein CreateUserWizard).
Anmerkung: Ich schreibe hier nur Testweise mal die "Answer" in die zusätzliche, in der web.config definierten, City-Profile Property. Das bleibt natürlich nicht so.
Wenn ich das ganze Konstrukt nun ausführe erhalte ich die Exception

ausblenden Quelltext
1:
2:
System.Web.HttpException was unhandled by user code
  Message="Unable to connect to SQL Server database."


In der InnerException stehen leider keine Details über die SQL Verbindung:

ausblenden Quelltext
1:
A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified)					


Nun, ich nehme an, er nimmt die Verbindung die in der web.config wie folgt definiert ist:

ausblenden XML-Daten
1:
2:
3:
  <connectionStrings>
    <add name="Davesworld" connectionString="data source=.;Database=davesworld;Uid=sa;Pwd=******"/>
  </connectionStrings>


Diese Connection wird auch von meine Membership Provier genutzt und ich kann problemlos Benutzer anlegen, lesen, etc. Also unterstelle ich, die tut. Wie bekomme ich nun raus, wie sich der Profile Provider zu verbinden versucht?

Hier zur Sicherheit auch noch mal die Profile Provier Konfig aus meiner web.config:

ausblenden XML-Daten
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
    <profile>
      <providers>
        <add name="DavesworldProfileProvider"
             connectionStringName="Davesworld"
             applicationName="/"
             type="System.Web.Profile.SqlProfileProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/>
      </providers>
      <properties>
        <add name="FirstName"/>
        <add name="LastName"/>
        <add name="Address1"/>
        <add name="Address2"/>
        <add name="City"/>
        <add name="Zip"/>
        <add name="ProfileVersion" type="int" defaultValue="0"/>
      </properties>
    </profile>


2) Gehe ich hier überhaupt den richtigen Weg? Das Problem ist ja so offensichtlich reproduzierbar, das ich mich wundere wie oft selbst die MSDN den Weg über die ProfileCommon Klasse beschreibt, ohne das das funktioniert. Wie löst Ihr diese Profile Anforderung? Macht Ihr das ganz anders? Stell ich mich blöd an?

Würde mich über zahlreiche Antworten freuen

Gruss Dave
kingdave2nd Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 54



BeitragVerfasst: Mi 29.07.09 12:15 
Ich hab die Lösung...

Im profile tag der web.config muss auch der defaultProviderProvider wie folgt eingetragen werden:

ausblenden C#-Quelltext
1:
<profile defaultProvider="DavesworldProfileProvider">					


Anonsten wird der default Provider aus der machine.config des systems verwendet (nehme ich an).
Ich markiere meinen kleine Monolog :lol: mal als gelöst und hoffe das ich dem einen oder anderen damit einen kleine Stolperstein voerweg nehmen kann ;-)

Gruss Dave