开发者

Asp.net profile in a separate assembly

开发者 https://www.devze.com 2023-01-01 13:25 出处:网络
I have a web application which uses membership and profiles.I successfully used the WebProfileBuilder extension, so my profile class is correctly generated, and is working nicely.

I have a web application which uses membership and profiles. I successfully used the WebProfileBuilder extension, so my profile class is correctly generated, and is working nicely.

However, after a new request of my client, I need now to move that profile management part into another assembly (so I'd be able to get profile inform开发者_C百科ation in a windows service running on the same machine).

What I made is created the new assembly, moved my generated profile file, and tried to use it from the other assembly, but without any success. I always get a SettingsPropertyNotFoundException. My thought is that the profile system doesn't know where to find its connection information, so I tried to add the connectionstring and provider in the app.config of this assembly, but this doesn't seem to work.

What am I missing ? Is it possible to do ?

Thanks in advance!


I've got a nasty suspicion that your APP.Config file won't be picked by the web application; did you keep the settings in your Web.Config file ?

I've only found app.config to work on such an assemply when using NUnit or similar.


Ok I found what's wrong... Thanks to this blog post:

http://fredrik.nsquared2.com/viewpost.aspx?postid=244&showfeedback=true

The only thing I needed to do is add applicationName="/" in my provider configuration, in the app.config. (which is the application name, can be found inside the aspnet_Applications table in the DB.

<configuration>

  <connectionStrings>
    <add
        name="MyConnectionString"
        connectionString="Data Source=...;Initial Catalog=...;User ID=...;Password=..."
        providerName="System.Data.SqlClient" />
  </connectionStrings>

  <system.web>
    <profile
      enabled="true"
      defaultProvider="Sql2008ProfileProvider">
      <properties>
        <add name="UserLevel" type="integer"/>
        <add name="value1" type="string" />
        <add name="value2" type="string"  />
        <add name="value3" type="string" />
        <add name="value4" type="string"/>
      </properties>

      <providers>
        <clear/>
        <add
            name="Sql2008ProfileProvider"
            type="System.Web.Profile.SqlProfileProvider"
            connectionStringName="MyConnectionString"
            applicationName="/"
            />
      </providers>

    </profile>
  </system.web>

</configuration>
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号