簡體   English   中英

如何在asp.net mvc 3中通過userId獲取配置文件信息?

[英]How to get profile info by userId in asp.net mvc 3?

我想實現用戶配置文件,以便其他用戶能夠看到它。

如何在asp.net mvc3中獲取有關特定用戶的個人資料信息?

這(簡而言之)是如何實現默認配置文件提供程序的。

在您的web.config中,添加

<profile>
      <providers>
        <clear/>
        <add name="AspNetSqlProfileProvider"
             type="System.Web.Profile.SqlProfileProvider"
             connectionStringName="ApplicationServices" 
             <!--same connection string as the membership provider-->
             applicationName="/"/>
      </providers>
      <properties>
        <add name="FirstName" type="string"/>
        <add name="LastName" type="string"/>
        <!--...or whatever profile properties you want/need-->
      </properties>
    </profile>

然后,您可以為配置文件屬性指定值

ProfileBase profile = ProfileBase.Create(userName);
profile["FirstName"] = "John";
profile["LastName"] = "Smith";

並閱讀價值觀

string firstName;
string lastName;
ProfileBase profile = ProfileBase.Create(userName);
firstName = profile["FirstName"] as string,
lastName = profile["LastName"] as string,

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM