2009-11-10 72 views
0

IM目前正試圖現在幾天就實施我的網站的個人資料提供者,有一個很難做這個工作,我是一個PHP程序設計師,我只是使用LINQ to SQL的轉向asp.net最近在ASP.net MVC中使用自定義配置文件提供程序?

林,並按照這個http://www.codeproject.com/KB/aspnet/LINQCustomProfileProvider.aspx教程。

即時通訊使用我自己的原因,因爲我有不同的結構比任何默認的asp.net有。配置文件數據在我的用戶表中。

編譯很好,登錄很好。

但我想

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

將無法​​正常工作,並拋出我System.NullReferenceException ......我 怎麼能自動獲得我的個人資料到HttpContext的,這樣我可以輕鬆地每次召喚出來。

如果您需要更多數據,我可以提供。

非常感謝。

Web.config文件:

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

回答

2

你如何註冊web.config中的供應商?您不應該自己實例化提供程序,它應該在啓動時由應用程序完成。如果您提供更多信息,我可能會提供幫助。

編輯:這是我的web.config,也許它會對你有所幫助。

<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> 
+0

我已經將web.config添加到了我的帖子中。你可以請退房 – DucDigital 2009-11-11 03:52:39

1

我注意到,文章的作者並沒有給出一個代碼示例結合探查或工作流來的HttpContext。

你寫過自己的班級嗎?如果是這樣,你有沒有在web.config中正確設置?

如果您使用IIS7,則還需要在web.config文件的webServer部分下注冊您的IHttpModule。

編輯

爲了能夠運行的代碼片斷你展現給你需要有放置您的自定義探查到的HttpContext。

您可以通過兩種方式執行此操作,無論是基於每個請求還是應用程序啓動。

對於每個請求的基礎,您需要創建一個實現IHttpModule的類並將其註冊到web.config中。

對於應用程序啓動,您需要將您的CMSProfile附加到Application_OnStart方法中的HttpContext.Current。

他們是附加到您發佈的文章的示例應用程序,你有下載和檢查示例應用程序?

+0

我不認爲這是事實,因爲註冊和登錄工作得很好。 – DucDigital 2009-11-11 03:53:12

+0

你如何將CMSProfile綁定到HttpContext? – 2009-11-11 09:37:54

+0

我不知道,我想我沒有這樣做。 – DucDigital 2009-11-11 13:19:03

相關問題