views:

482

answers:

2

Hello, im currently trying to implement a profile provider for my site a few days now and having a hard time working on it, im a php programer and i just shift to asp.net recently

Im using Linq to sql and follow this http://www.codeproject.com/KB/aspnet/LINQCustomProfileProvider.aspx tutorial.

the reason im using my own because i having different structure than any default of asp.net have. The profile data is inside my user table.

The compile was fine, login was fine.

but i tried

<% CMSProfile profile = HttpContext.Current.Profile as CMSProfile;%>
<%= profile.NickName %>

it won't work and throw me a System.NullReferenceException... so how can i automatically get my Profile into the HTTPCONtext so that i can call out easily everytime.

If you need any more data, i can provide.

Thank you very much.

Web.config:

<roleManager enabled="false" defaultProvider="CMSRoleProvider">
  <providers>
    <clear />
    <add name="CMSRoleProvider" type="P014.ProviderClass.CMSRoleProvider" connectionStringName="P014ConnectionString" applicationName="/" />
  </providers>
</roleManager>
+1  A: 

How have you registered the provider in web.config? You shouldn't have to instantiate the provider yourself it should be done by the app at startup. If you give more info I might be able to help.

EDIT: Here is my web.config, maybe it will be of help to you.

<profile defaultProvider="SWIntranetProfile" enabled="true">
    <providers>
     <clear/>
     <add name="SWIntranetProfile" type="SWIntranetProfile"/>
    </providers>
    <properties>
     <clear/>
     <!-- SID is really LOGON_USER -->
     <add name="SID" allowAnonymous="false" type="System.String" readOnly="true"/>
     <add name="PersonID" allowAnonymous="false" type="System.Int32" readOnly="true"/>
     <add name="EmailAddress" allowAnonymous="false" type="System.String" readOnly="true"/>
     <add name="Position" allowAnonymous="false" type="System.String" readOnly="true"/>
     <add name="Name" allowAnonymous="false" type="System.String" readOnly="true"/>
     <add name="FirstName" allowAnonymous="false" type="System.String" readOnly="true"/>
     <add name="LastName" allowAnonymous="false" type="System.String" readOnly="true"/>
     <add name="ImageName" allowAnonymous="false" type="System.String" readOnly="true"/>
     <add name="PhoneExt" allowAnonymous="false" type="System.String" readOnly="true"/>
     <add name="LastIP" allowAnonymous="false" type="System.String" readOnly="false"/>
     <add name="IntranetTheme" allowAnonymous="false" type="System.String" readOnly="false"/>
     <add name="UnionID" allowAnonymous="false" type="System.Int32" readOnly="true"/>
     <add name="UnionName" allowAnonymous="false" type="System.String" readOnly="true"/>
     <add name="OfficeID" allowAnonymous="false" type="System.Int32" readOnly="true"/>
    </properties>
</profile>
Lukasz
i've added the web.config to my post. can you please check out
DucDigital
+1  A: 

I noticed that the author of the article didn't give a code sample for binding the profiler or Workflow to the HttpContext.

Have you written your own class to do this? If so, have you set this up correctly in the web.config?

If your using IIS7 you also need to register your IHttpModule under the webServer section of the web.config file.

EDIT

To be able to run the code snippet you have show to you need to have placed your custom Profiler to the HttpContext.

You can do this in two ways, either on a per request basis or on the application start.

For the per request basis you would need to create a class that implements IHttpModule and register it in the web.config.

For the Application start you need to attach your CMSProfile to the HttpContext.Current in the Application_OnStart method.

Their is a sample application attached to the article you posted, have you downloading and checked sample application?

theouteredge
i dont think it's the case because the registration and login work just fine.
DucDigital
How are you binding the CMSProfile to the HttpContext?
theouteredge
i dont know, i tthink i havent' do that.
DucDigital
I've edited my answer
theouteredge
is the data of ProfileProvider store in HttpContext is the same as Session storage? which mean i do not have to query from database again? i've read some where else that the ProfileProvider once query it wont query from database again. is it correct? :) Thanks so much
DucDigital
I'm not a 100% sure about the lifecycle of the HttpContext, but I think if you set your instance in the Application_OnStart then that instance should last for the life of your website.
theouteredge