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

时间:2021-02-03 03:38:40

I want to implement user profile, so other users will be able to see it.

我想实现用户配置文件,以便其他用户能够看到它。

How can I get profile info about a particular user by it's id in asp.net mvc3??

如何在asp.net mvc3中获取有关特定用户的个人资料信息?

1 个解决方案

#1


2  

This is (in a nutshell) how you would implement the default profile provider.

这(简而言之)是如何实现默认配置文件提供程序的。

In your web.config, add

在您的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>

Then you can assign values to the profile properties

然后,您可以为配置文件属性指定值

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

And read the values

并阅读价值观

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

#1


2  

This is (in a nutshell) how you would implement the default profile provider.

这(简而言之)是如何实现默认配置文件提供程序的。

In your web.config, add

在您的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>

Then you can assign values to the profile properties

然后,您可以为配置文件属性指定值

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

And read the values

并阅读价值观

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