VS2005提供的Webparts控件,的确是好东西,不过需要的先决条件太苛刻了!按照微软的说法,需要安装SQLExpress,可惜我按装了SQL2005 Server,呵呵,自己好管理数据库啊!使用webparts需要经过身份验证才能看到,我搞了一个礼拜,郁闷,到处找Webparts的资料,还和Sharepoint扯上了关系,后来还是觉得自己摸索摸索吧,先把成员管理给搞定了。成员管理用的几个类Membership,Roles,等等Provider的东西,微软提供好了,用起来特方便,不过先决条件说的不明不白的!
后来自己看了C:\windows\Microsof Net\Config\maching.config文件,才搞明白,它里面成员是这样定义的:
<
system.web
>
<
processModel autoConfig
=
"
true
"
/>
<
httpHandlers
/>
<
membership
>
<
providers
>
<
add name
=
"
AspNetSqlMembershipProvider
"
type
=
"
System.Web.Security.SqlMembershipProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
"
connectionStringName
=
"
LocalSqlServer
"
enablePasswordRetrieval
=
"
false
"
enablePasswordReset
=
"
true
"
requiresQuestionAndAnswer
=
"
true
"
applicationName
=
"
/
"
requiresUniqueEmail
=
"
false
"
passwordFormat
=
"
Hashed
"
maxInvalidPasswordAttempts
=
"
5
"
minRequiredPasswordLength
=
"
7
"
minRequiredNonalphanumericCharacters
=
"
1
"
passwordAttemptWindow
=
"
10
"
passwordStrengthRegularExpression
=
""
/>
</
providers
>
</
membership
>
<
profile
>
<
providers
>
<
add name
=
"
AspNetSqlProfileProvider
"
connectionStringName
=
"
LocalSqlServer
"
applicationName
=
"
/
"
type
=
"
System.Web.Profile.SqlProfileProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
"
/>
</
providers
>
</
profile
>
<
roleManager
>
<
providers
>
<
add name
=
"
AspNetSqlRoleProvider
"
connectionStringName
=
"
LocalSqlServer
"
applicationName
=
"
/
"
type
=
"
System.Web.Security.SqlRoleProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
"
/>
<
add name
=
"
AspNetWindowsTokenRoleProvider
"
applicationName
=
"
/
"
type
=
"
System.Web.Security.WindowsTokenRoleProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
"
/>
</
providers
>
</
roleManager
>
</
system.web
>
使用connectionStringName="LocalSqlServer",还是在maching.config看看他对这个链接怎么定义的!
<
connectionStrings
>
<
add name
=
"
LocalSqlServer
"
connectionString
=
"
data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|aspnetdb.mdf;User Instance=true
"
providerName
=
"
System.Data.SqlClient
"
/>
</
connectionStrings
>
嗯,看得的出来,太不厚道了,竟然用SQLEXPRESS默认的SQL接点名.难怪要装SQLExpress呢!
我改!!
<
connectionStrings
>
<
add name
=
"
SqlConnection
"
connectionString
=
"
data source=WUHANG;Initial Catalog=aspnetdb;User=sa;Password=123456
"
providerName
=
"
System.Data.SqlClient
"
/>
<!--<
add name
=
"
SqlConnection
"
connectionString
=
"
data source=WUHaNG;AttachDbFilename=|DataDirectory|aspnetdb.mdf;Integrated Security=False;User ID=sa;Password=123456
"
providerName
=
"
System.Data.SqlClient
"
/>-->
</
connectionStrings
>
呵呵,改称我自己的链接!
然后再把MemberProvider哪些配置改一改!
<
membership
>
<
providers
>
<
remove name
=
"
AspNetSqlMembershipProvider
"
/>
<
add name
=
"
AspNetSqlMembershipProvider
"
type
=
"
System.Web.Security.SqlMembershipProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
"
connectionStringName
=
"
SqlConnection
"
enablePasswordRetrieval
=
"
false
"
enablePasswordReset
=
"
true
"
requiresQuestionAndAnswer
=
"
true
"
applicationName
=
"
/
"
requiresUniqueEmail
=
"
false
"
passwordFormat
=
"
Hashed
"
maxInvalidPasswordAttempts
=
"
5
"
minRequiredPasswordLength
=
"
4
"
minRequiredNonalphanumericCharacters
=
"
0
"
passwordAttemptWindow
=
"
10
"
passwordStrengthRegularExpression
=
""
/>
</
providers
>
</
membership
>
<
profile
>
<
providers
>
<
remove name
=
"
AspNetSqlProfileProvider
"
/>
<
add name
=
"
AspNetSqlProfileProvider
"
connectionStringName
=
"
SqlConnection
"
applicationName
=
"
/
"
type
=
"
System.Web.Profile.SqlProfileProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
"
/>
</
providers
>
</
profile
>
<
roleManager enabled
=
"
true
"
>
<
providers
>
<
remove name
=
"
AspNetSqlRoleProvider
"
/>
<
add connectionStringName
=
"
SqlConnection
"
applicationName
=
"
/
"
name
=
"
AspNetSqlRoleProvider
"
type
=
"
System.Web.Security.SqlRoleProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
"
/>
</
providers
>
</
roleManager
>
呵呵,改成我自己的链接Provider了!
对了数据库还没建立呢!!赶紧的去C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\aspnet_regsql.exe,运行一下,呵呵,自动在我数据库里面创建了个数据库,叫aspnetdb,名字随便在SQL2005Server里面改,改完了记得把Config文件里面连接数据的名字也给改了!
OK 做了上面的设置后,就可以使用哪些登陆控件啦!!
然后开始配置WebParts控件,哪些控件需要在登陆后才能使用!先整一个CreateUser控件,天加个用户再说,数据库里面有新用户了,在整一个Login控件,登陆下,登陆后指向个空白页,就在那个页面里面放WebPart控件就OK啦!
一运行,我晕,竟然来个服务器没开26端口!靠咋整的,链接不是搞定了嘛!
我那个郁闷呀。。。。郁闷呀。。。郁闷呀!
一天以后看到可以配置Webparts的说法,赶紧那个找呀,靠太不厚道,maching.config里面没有那个webparts配置节,那个郁闷呀,该咋整呢,说时迟那时快,突然在同一目录下发现了个叫web.config的文件,甚是可爱,打开一瞄,我考这里有哎!!!
<
webParts
>
<
personalization
>
<
providers
>
<
add connectionStringName
=
"
LocalSqlServer
"
name
=
"
AspNetSqlPersonalizationProvider
"
type
=
"
System.Web.UI.WebControls.WebParts.SqlPersonalizationProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
"
/>
</
providers
>
<
authorization
>
<
deny users
=
"
*
"
verbs
=
"
enterSharedScope
"
/>
<
allow users
=
"
*
"
verbs
=
"
modifyState
"
/>
</
authorization
>
</
personalization
>
<
transformers
>
<
add name
=
"
RowToFieldTransformer
"
type
=
"
System.Web.UI.WebControls.WebParts.RowToFieldTransformer
"
/>
<
add name
=
"
RowToParametersTransformer
"
type
=
"
System.Web.UI.WebControls.WebParts.RowToParametersTransformer
"
/>
</
transformers
>
</
webParts
>
哈哈,世界如此美妙!!
整成我要的样子!
<
webParts
>
<
personalization
>
<
providers
>
<
clear
/>
<
add connectionStringName
=
"
SqlConnection
"
name
=
"
AspNetSqlPersonalizationProvider
"
type
=
"
System.Web.UI.WebControls.WebParts.SqlPersonalizationProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
"
/>
</
providers
>
<!--<
authorization
>
<
clear
/>
<
deny users
=
"
?
"
verbs
=
"
enterSharedScope
"
/>
<
allow roles
=
"
Administrators
"
verbs
=
"
modifyState
"
/>
</
authorization
>-->
</
personalization
>
<
transformers
>
<
clear
/>
<
add name
=
"
RowToFieldTransformer
"
type
=
"
System.Web.UI.WebControls.WebParts.RowToFieldTransformer
"
/>
<
add name
=
"
RowToParametersTransformer
"
type
=
"
System.Web.UI.WebControls.WebParts.RowToParametersTransformer
"
/>
</
transformers
>
</
webParts
>
里面几个配置不知道啥意思,就弄了第一个connectionStringName="SqlConnection",换成我提供的链接名字,哈哈,这下运行起来可以看到Webparts那神秘而又美丽的身影咯!不过怎么去摆弄那美丽而又神秘的身影,还在研究中!