自定义MemberShipProvider和PersonalizationProvider使用WebParts实现个性化页面
自定义MemberShipProvider和PersonalizationProvider使用WebParts实现个性化页面
现有一个系统,登录注册等都写好了,想要使用WebParts实现用户个性化页面,于是。。。
首先需要一张表来存放个性化数据,基本上就是从ASP.NET自带的某个表:
PersonalizationPerUser
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[PersonalizationPerUser](
[Id] [uniqueidentifier] NOT NULL CONSTRAINT [DF__Personalizat__Id__5244F976] DEFAULT (newid()),
[Path] [nvarchar](4000) NOT NULL,
[UserId] [uniqueidentifier] NOT NULL,
[PageSettings] [image] NOT NULL,
[LastUpdatedDate] [datetime] NOT NULL,
CONSTRAINT [PK__PersonalizationP__5150D53D] PRIMARY KEY NONCLUSTERED
(
[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[PersonalizationPerUser](
[Id] [uniqueidentifier] NOT NULL CONSTRAINT [DF__Personalizat__Id__5244F976] DEFAULT (newid()),
[Path] [nvarchar](4000) NOT NULL,
[UserId] [uniqueidentifier] NOT NULL,
[PageSettings] [image] NOT NULL,
[LastUpdatedDate] [datetime] NOT NULL,
CONSTRAINT [PK__PersonalizationP__5150D53D] PRIMARY KEY NONCLUSTERED
(
[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
然后是自己的MembershipProvider,不用实现全部的方法:
PortalMembershipProvider
public class PortalMembershipProvider : MembershipProvider
{
public override string ApplicationName
{
get
{
throw new Exception("The method or operation is not implemented.");
}
set
{
throw new Exception("The method or operation is not implemented.");
}
}
public override bool ChangePassword(string username, string oldPassword, string newPassword)
{
throw new Exception("The method or operation is not implemented.");
}
public override bool ChangePasswordQuestionAndAnswer(string username, string password, string newPasswordQuestion, string newPasswordAnswer)
{
throw new Exception("The method or operation is not implemented.");
}
public override MembershipUser CreateUser(string username, string password, string email, string passwordQuestion, string passwordAnswer, bool isApproved, object providerUserKey, out MembershipCreateStatus status)
{
throw new Exception("The method or operation is not implemented.");
}
public override bool DeleteUser(string username, bool deleteAllRelatedData)
{
throw new Exception("The method or operation is not implemented.");
}
public override bool EnablePasswordReset
{
get { throw new Exception("The method or operation is not implemented."); }
}
public override bool EnablePasswordRetrieval
{
get { throw new Exception("The method or operation is not implemented."); }
}
public override MembershipUserCollection FindUsersByEmail(string emailToMatch, int pageIndex, int pageSize, out int totalRecords)
{
throw new Exception("The method or operation is not implemented.");
}
public override MembershipUserCollection FindUsersByName(string usernameToMatch, int pageIndex, int pageSize, out int totalRecords)
{
throw new Exception("The method or operation is not implemented.");
}
public override MembershipUserCollection GetAllUsers(int pageIndex, int pageSize, out int totalRecords)
{
throw new Exception("The method or operation is not implemented.");
}
public override int GetNumberOfUsersOnline()
{
throw new Exception("The method or operation is not implemented.");
}
public override string GetPassword(string username, string answer)
{
throw new Exception("The method or operation is not implemented.");
}
public override MembershipUser GetUser(string username, bool userIsOnline)
{
using (Common.Data.UserInformationData
userData = new BusinessFacade.PersonalizationSystem().GetUser(username,
userIsOnline))
{
MembershipUser user = null;
if (userData != null
&& userData.UserInformation.Count == 1)
{
Common.Data.UserInformationData.UserInformationRow userRow
= userData.UserInformation[0];
DateTime lastLoginDate = userRow.IsLastLoginDateNull() ? userRow.CreateDate : userRow.LastLoginDate;
user = new MembershipUser(
this.Name,
username,
userRow.ID,
userRow.Email,
userRow.PasswordQuestion,
string.Empty,
true,
false,
userRow.CreateDate,
lastLoginDate,
lastLoginDate,
DateTime.MinValue,
DateTime.MinValue);
}
return user;
}
}
public override MembershipUser GetUser(object providerUserKey, bool userIsOnline)
{
using (Common.Data.UserInformationData
userData = new BusinessFacade.PersonalizationSystem().GetUser(providerUserKey,
userIsOnline))
{
MembershipUser user = null;
if (userData != null
&& userData.UserInformation.Count == 1)
{
Common.Data.UserInformationData.UserInformationRow userRow
= userData.UserInformation[0];
DateTime lastLoginDate = userRow.IsLastLoginDateNull() ? userRow.CreateDate : userRow.LastLoginDate;
user = new MembershipUser(
this.Name,
userRow.UserName,
userRow.ID,
userRow.Email,
userRow.PasswordQuestion,
string.Empty,
true,
false,
userRow.CreateDate,
lastLoginDate,
lastLoginDate,
DateTime.MinValue,
DateTime.MinValue);
}
return user;
}
}
public override string GetUserNameByEmail(string email)
{
throw new Exception("The method or operation is not implemented.");
}
public override int MaxInvalidPasswordAttempts
{
get { throw new Exception("The method or operation is not implemented."); }
}
public override int MinRequiredNonAlphanumericCharacters
{
get { throw new Exception("The method or operation is not implemented."); }
}
public override int MinRequiredPasswordLength
{
get { throw new Exception("The method or operation is not implemented."); }
}
public override int PasswordAttemptWindow
{
get { throw new Exception("The method or operation is not implemented."); }
}
public override MembershipPasswordFormat PasswordFormat
{
get { throw new Exception("The method or operation is not implemented."); }
}
public override string PasswordStrengthRegularExpression
{
get { throw new Exception("The method or operation is not implemented."); }
}
public override bool RequiresQuestionAndAnswer
{
get { throw new Exception("The method or operation is not implemented."); }
}
public override bool RequiresUniqueEmail
{
get { throw new Exception("The method or operation is not implemented."); }
}
public override string ResetPassword(string username, string answer)
{
throw new Exception("The method or operation is not implemented.");
}
public override bool UnlockUser(string userName)
{
throw new Exception("The method or operation is not implemented.");
}
public override void UpdateUser(MembershipUser user)
{
throw new Exception("The method or operation is not implemented.");
}
public override bool ValidateUser(string username, string password)
{
throw new Exception("The method or operation is not implemented.");
}
}
public class PortalMembershipProvider : MembershipProvider
{
public override string ApplicationName
{
get
{
throw new Exception("The method or operation is not implemented.");
}
set
{
throw new Exception("The method or operation is not implemented.");
}
}
public override bool ChangePassword(string username, string oldPassword, string newPassword)
{
throw new Exception("The method or operation is not implemented.");
}
public override bool ChangePasswordQuestionAndAnswer(string username, string password, string newPasswordQuestion, string newPasswordAnswer)
{
throw new Exception("The method or operation is not implemented.");
}
public override MembershipUser CreateUser(string username, string password, string email, string passwordQuestion, string passwordAnswer, bool isApproved, object providerUserKey, out MembershipCreateStatus status)
{
throw new Exception("The method or operation is not implemented.");
}
public override bool DeleteUser(string username, bool deleteAllRelatedData)
{
throw new Exception("The method or operation is not implemented.");
}
public override bool EnablePasswordReset
{
get { throw new Exception("The method or operation is not implemented."); }
}
public override bool EnablePasswordRetrieval
{
get { throw new Exception("The method or operation is not implemented."); }
}
public override MembershipUserCollection FindUsersByEmail(string emailToMatch, int pageIndex, int pageSize, out int totalRecords)
{
throw new Exception("The method or operation is not implemented.");
}
public override MembershipUserCollection FindUsersByName(string usernameToMatch, int pageIndex, int pageSize, out int totalRecords)
{
throw new Exception("The method or operation is not implemented.");
}
public override MembershipUserCollection GetAllUsers(int pageIndex, int pageSize, out int totalRecords)
{
throw new Exception("The method or operation is not implemented.");
}
public override int GetNumberOfUsersOnline()
{
throw new Exception("The method or operation is not implemented.");
}
public override string GetPassword(string username, string answer)
{
throw new Exception("The method or operation is not implemented.");
}
public override MembershipUser GetUser(string username, bool userIsOnline)
{
using (Common.Data.UserInformationData
userData = new BusinessFacade.PersonalizationSystem().GetUser(username,
userIsOnline))
{
MembershipUser user = null;
if (userData != null
&& userData.UserInformation.Count == 1)
{
Common.Data.UserInformationData.UserInformationRow userRow
= userData.UserInformation[0];
DateTime lastLoginDate = userRow.IsLastLoginDateNull() ? userRow.CreateDate : userRow.LastLoginDate;
user = new MembershipUser(
this.Name,
username,
userRow.ID,
userRow.Email,
userRow.PasswordQuestion,
string.Empty,
true,
false,
userRow.CreateDate,
lastLoginDate,
lastLoginDate,
DateTime.MinValue,
DateTime.MinValue);
}
return user;
}
}
public override MembershipUser GetUser(object providerUserKey, bool userIsOnline)
{
using (Common.Data.UserInformationData
userData = new BusinessFacade.PersonalizationSystem().GetUser(providerUserKey,
userIsOnline))
{
MembershipUser user = null;
if (userData != null
&& userData.UserInformation.Count == 1)
{
Common.Data.UserInformationData.UserInformationRow userRow
= userData.UserInformation[0];
DateTime lastLoginDate = userRow.IsLastLoginDateNull() ? userRow.CreateDate : userRow.LastLoginDate;
user = new MembershipUser(
this.Name,
userRow.UserName,
userRow.ID,
userRow.Email,
userRow.PasswordQuestion,
string.Empty,
true,
false,
userRow.CreateDate,
lastLoginDate,
lastLoginDate,
DateTime.MinValue,
DateTime.MinValue);
}
return user;
}
}
public override string GetUserNameByEmail(string email)
{
throw new Exception("The method or operation is not implemented.");
}
public override int MaxInvalidPasswordAttempts
{
get { throw new Exception("The method or operation is not implemented."); }
}
public override int MinRequiredNonAlphanumericCharacters
{
get { throw new Exception("The method or operation is not implemented."); }
}
public override int MinRequiredPasswordLength
{
get { throw new Exception("The method or operation is not implemented."); }
}
public override int PasswordAttemptWindow
{
get { throw new Exception("The method or operation is not implemented."); }
}
public override MembershipPasswordFormat PasswordFormat
{
get { throw new Exception("The method or operation is not implemented."); }
}
public override string PasswordStrengthRegularExpression
{
get { throw new Exception("The method or operation is not implemented."); }
}
public override bool RequiresQuestionAndAnswer
{
get { throw new Exception("The method or operation is not implemented."); }
}
public override bool RequiresUniqueEmail
{
get { throw new Exception("The method or operation is not implemented."); }
}
public override string ResetPassword(string username, string answer)
{
throw new Exception("The method or operation is not implemented.");
}
public override bool UnlockUser(string userName)
{
throw new Exception("The method or operation is not implemented.");
}
public override void UpdateUser(MembershipUser user)
{
throw new Exception("The method or operation is not implemented.");
}
public override bool ValidateUser(string username, string password)
{
throw new Exception("The method or operation is not implemented.");
}
}
还有自己的PersonalizationProvider,也只实现了两个方法:
PortalPersonalizationProvider
public class PortalPersonalizationProvider : PersonalizationProvider
{
public override string ApplicationName
{
get
{
throw new Exception("The method or operation is not implemented.");
}
set
{
throw new Exception("The method or operation is not implemented.");
}
}
public override PersonalizationStateInfoCollection FindState(PersonalizationScope scope, PersonalizationStateQuery query, int pageIndex, int pageSize, out int totalRecords)
{
throw new Exception("The method or operation is not implemented.");
}
public override int GetCountOfState(PersonalizationScope scope, PersonalizationStateQuery query)
{
throw new Exception("The method or operation is not implemented.");
}
protected override void LoadPersonalizationBlobs(WebPartManager webPartManager, string path, string userName, ref byte[] sharedDataBlob, ref byte[] userDataBlob)
{
if (string.IsNullOrEmpty(path)
|| string.IsNullOrEmpty(userName))
{
return;
}
new BusinessFacade.PersonalizationSystem().LoadPersonalizationBlobs(path,
userName,
ref userDataBlob);
}
protected override void ResetPersonalizationBlob(WebPartManager webPartManager, string path, string userName)
{
throw new Exception("The method or operation is not implemented.");
}
public override int ResetState(PersonalizationScope scope, string[] paths, string[] usernames)
{
throw new Exception("The method or operation is not implemented.");
}
public override int ResetUserState(string path, DateTime userInactiveSinceDate)
{
throw new Exception("The method or operation is not implemented.");
}
protected override void SavePersonalizationBlob(WebPartManager webPartManager, string path, string userName, byte[] dataBlob)
{
if (string.IsNullOrEmpty(path)
|| string.IsNullOrEmpty(userName))
{
return;
}
new BusinessFacade.PersonalizationSystem().SavePersonalizationBlob(path,
userName,
dataBlob);
}
public class PortalPersonalizationProvider : PersonalizationProvider
{
public override string ApplicationName
{
get
{
throw new Exception("The method or operation is not implemented.");
}
set
{
throw new Exception("The method or operation is not implemented.");
}
}
public override PersonalizationStateInfoCollection FindState(PersonalizationScope scope, PersonalizationStateQuery query, int pageIndex, int pageSize, out int totalRecords)
{
throw new Exception("The method or operation is not implemented.");
}
public override int GetCountOfState(PersonalizationScope scope, PersonalizationStateQuery query)
{
throw new Exception("The method or operation is not implemented.");
}
protected override void LoadPersonalizationBlobs(WebPartManager webPartManager, string path, string userName, ref byte[] sharedDataBlob, ref byte[] userDataBlob)
{
if (string.IsNullOrEmpty(path)
|| string.IsNullOrEmpty(userName))
{
return;
}
new BusinessFacade.PersonalizationSystem().LoadPersonalizationBlobs(path,
userName,
ref userDataBlob);
}
protected override void ResetPersonalizationBlob(WebPartManager webPartManager, string path, string userName)
{
throw new Exception("The method or operation is not implemented.");
}
public override int ResetState(PersonalizationScope scope, string[] paths, string[] usernames)
{
throw new Exception("The method or operation is not implemented.");
}
public override int ResetUserState(string path, DateTime userInactiveSinceDate)
{
throw new Exception("The method or operation is not implemented.");
}
protected override void SavePersonalizationBlob(WebPartManager webPartManager, string path, string userName, byte[] dataBlob)
{
if (string.IsNullOrEmpty(path)
|| string.IsNullOrEmpty(userName))
{
return;
}
new BusinessFacade.PersonalizationSystem().SavePersonalizationBlob(path,
userName,
dataBlob);
}
底层的代码不贴了就。
接着是web.config
system.web
<system.web>
<membership defaultProvider="PortalMembershipProvider">
<providers>
<clear/>
<add name="PortalMembershipProvider" type="Portal.WebUI.Personalization.PortalMembershipProvider"/>
</providers>
</membership>
<webParts>
<personalization defaultProvider="PortalPersonalizationProvider">
<providers>
<clear/>
<add name="PortalPersonalizationProvider" type="Portal.WebUI.Personalization.PortalPersonalizationProvider"/>
</providers>
</personalization>
</webParts>
</system.web>
<system.web>
<membership defaultProvider="PortalMembershipProvider">
<providers>
<clear/>
<add name="PortalMembershipProvider" type="Portal.WebUI.Personalization.PortalMembershipProvider"/>
</providers>
</membership>
<webParts>
<personalization defaultProvider="PortalPersonalizationProvider">
<providers>
<clear/>
<add name="PortalPersonalizationProvider" type="Portal.WebUI.Personalization.PortalPersonalizationProvider"/>
</providers>
</personalization>
</webParts>
</system.web>
再接着就是aspx页面了:
Default.aspx
<%@ Page Language="C#" AutoEventWireup="true" Codebehind="Default.aspx.cs" Inherits="Portal.WebUI.Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>无标题页</title>
</head>
<body>
<form runat="server">
<div>
<asp:WebPartManager ID="WebPartManager1" runat="server">
</asp:WebPartManager>
<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged">
<asp:ListItem Value="0">请选择</asp:ListItem>
<asp:ListItem>Browse</asp:ListItem>
<asp:ListItem>Design</asp:ListItem>
<asp:ListItem>Edit</asp:ListItem>
<asp:ListItem>Catalog</asp:ListItem>
<asp:ListItem>Connect</asp:ListItem>
</asp:DropDownList>
</div>
<asp:WebPartZone ID="WebPartZone1" runat="server" BorderColor="#CCCCCC" Font-Names="Verdana" Padding="6">
<ZoneTemplate>
</ZoneTemplate>
<PartChromeStyle BackColor="#F7F6F3" BorderColor="#E2DED6" Font-Names="Verdana" ForeColor="White" />
<MenuLabelHoverStyle ForeColor="#E2DED6" />
<EmptyZoneTextStyle Font-Size="0.8em" />
<MenuLabelStyle ForeColor="White" />
<MenuVerbHoverStyle BackColor="#F7F6F3" BorderColor="#CCCCCC" BorderStyle="Solid"
BorderWidth="1px" ForeColor="#333333" />
<HeaderStyle Font-Size="0.7em" ForeColor="#CCCCCC" HorizontalAlign="Center" />
<MenuVerbStyle BorderColor="#5D7B9D" BorderStyle="Solid" BorderWidth="1px" ForeColor="White" />
<PartStyle Font-Size="0.8em" ForeColor="#333333" />
<TitleBarVerbStyle Font-Size="0.6em" Font-Underline="False" ForeColor="White" />
<MenuPopupStyle BackColor="#5D7B9D" BorderColor="#CCCCCC" BorderWidth="1px" Font-Names="Verdana"
Font-Size="0.6em" />
<PartTitleStyle BackColor="#5D7B9D" Font-Bold="True" Font-Size="0.8em" ForeColor="White" />
</asp:WebPartZone>
<asp:WebPartZone ID="WebPartZone2" runat="server" BorderColor="#CCCCCC" Font-Names="Verdana" Padding="6">
<PartChromeStyle BackColor="#F7F6F3" BorderColor="#E2DED6" Font-Names="Verdana" ForeColor="White" />
<MenuLabelHoverStyle ForeColor="#E2DED6" />
<EmptyZoneTextStyle Font-Size="0.8em" />
<MenuLabelStyle ForeColor="White" />
<MenuVerbHoverStyle BackColor="#F7F6F3" BorderColor="#CCCCCC" BorderStyle="Solid"
BorderWidth="1px" ForeColor="#333333" />
<HeaderStyle Font-Size="0.7em" ForeColor="#CCCCCC" HorizontalAlign="Center" />
<ZoneTemplate>
<asp:Calendar ID="Calendar1" runat="server" BackColor="#FFFFCC" BorderColor="#FFCC66"
BorderWidth="1px" DayNameFormat="Shortest" Font-Names="Verdana" Font-Size="8pt"
ForeColor="#663399" Height="200px" ShowGridLines="True" Width="220px">
<SelectedDayStyle BackColor="#CCCCFF" Font-Bold="True" />
<TodayDayStyle BackColor="#FFCC66" ForeColor="White" />
<SelectorStyle BackColor="#FFCC66" />
<OtherMonthDayStyle ForeColor="#CC9966" />
<NextPrevStyle Font-Size="9pt" ForeColor="#FFFFCC" />
<DayHeaderStyle BackColor="#FFCC66" Font-Bold="True" Height="1px" />
<TitleStyle BackColor="#990000" Font-Bold="True" Font-Size="9pt" ForeColor="#FFFFCC" />
</asp:Calendar>
</ZoneTemplate>
<MenuVerbStyle BorderColor="#5D7B9D" BorderStyle="Solid" BorderWidth="1px" ForeColor="White" />
<PartStyle Font-Size="0.8em" ForeColor="#333333" />
<TitleBarVerbStyle Font-Size="0.6em" Font-Underline="False" ForeColor="White" />
<MenuPopupStyle BackColor="#5D7B9D" BorderColor="#CCCCCC" BorderWidth="1px" Font-Names="Verdana"
Font-Size="0.6em" />
<PartTitleStyle BackColor="#5D7B9D" Font-Bold="True" Font-Size="0.8em" ForeColor="White" />
</asp:WebPartZone>
<asp:EditorZone ID="EditorZone1" runat="server" BackColor="#F7F6F3" BorderColor="#CCCCCC"
BorderWidth="1px" Font-Names="Verdana" Padding="6">
<HeaderStyle BackColor="#E2DED6" Font-Bold="True" Font-Size="0.8em" ForeColor="#333333" />
<LabelStyle Font-Size="0.8em" ForeColor="#333333" />
<HeaderVerbStyle Font-Bold="False" Font-Size="0.8em" Font-Underline="False" ForeColor="#333333" />
<PartChromeStyle BorderColor="#E2DED6" BorderStyle="Solid" BorderWidth="1px" />
<PartStyle BorderColor="#F7F6F3" BorderWidth="5px" />
<FooterStyle BackColor="#E2DED6" HorizontalAlign="Right" />
<EditUIStyle Font-Names="Verdana" Font-Size="0.8em" ForeColor="#333333" />
<InstructionTextStyle Font-Size="0.8em" ForeColor="#333333" />
<ErrorStyle Font-Size="0.8em" />
<VerbStyle Font-Names="Verdana" Font-Size="0.8em" ForeColor="#333333" />
<EmptyZoneTextStyle Font-Size="0.8em" ForeColor="#333333" />
<PartTitleStyle Font-Bold="True" Font-Size="0.8em" ForeColor="#333333" />
<ZoneTemplate>
<asp:LayoutEditorPart ID="LayoutEditorPart1" runat="server" />
<asp:AppearanceEditorPart ID="AppearanceEditorPart1" runat="server" />
<asp:BehaviorEditorPart ID="BehaviorEditorPart1" runat="server" />
<asp:PropertyGridEditorPart ID="PropertyGridEditorPart1" runat="server" />
</ZoneTemplate>
</asp:EditorZone>
<asp:CatalogZone ID="CatalogZone1" runat="server" BackColor="#F7F6F3" BorderColor="#CCCCCC"
BorderWidth="1px" Font-Names="Verdana" Padding="6">
<HeaderVerbStyle Font-Bold="False" Font-Size="0.8em" Font-Underline="False" ForeColor="#333333" />
<PartTitleStyle BackColor="#5D7B9D" Font-Bold="True" Font-Size="0.8em" ForeColor="White" />
<PartChromeStyle BorderColor="#E2DED6" BorderStyle="Solid" BorderWidth="1px" />
<InstructionTextStyle Font-Size="0.8em" ForeColor="#333333" />
<PartLinkStyle Font-Size="0.8em" />
<EmptyZoneTextStyle Font-Size="0.8em" ForeColor="#333333" />
<LabelStyle Font-Size="0.8em" ForeColor="#333333" />
<VerbStyle Font-Names="Verdana" Font-Size="0.8em" ForeColor="#333333" />
<ZoneTemplate>
<asp:PageCatalogPart ID="PageCatalogPart1" runat="server" />
<asp:DeclarativeCatalogPart ID="DeclarativeCatalogPart1" runat="server">
<WebPartsTemplate>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
</WebPartsTemplate>
</asp:DeclarativeCatalogPart>
</ZoneTemplate>
<PartStyle BorderColor="#F7F6F3" BorderWidth="5px" />
<SelectedPartLinkStyle Font-Size="0.8em" />
<FooterStyle BackColor="#E2DED6" HorizontalAlign="Right" />
<HeaderStyle BackColor="#E2DED6" Font-Bold="True" Font-Size="0.8em" ForeColor="#333333" />
<EditUIStyle Font-Names="Verdana" Font-Size="0.8em" ForeColor="#333333" />
</asp:CatalogZone>
</form>
</body>
</html>
<%@ Page Language="C#" AutoEventWireup="true" Codebehind="Default.aspx.cs" Inherits="Portal.WebUI.Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>无标题页</title>
</head>
<body>
<form runat="server">
<div>
<asp:WebPartManager ID="WebPartManager1" runat="server">
</asp:WebPartManager>
<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged">
<asp:ListItem Value="0">请选择</asp:ListItem>
<asp:ListItem>Browse</asp:ListItem>
<asp:ListItem>Design</asp:ListItem>
<asp:ListItem>Edit</asp:ListItem>
<asp:ListItem>Catalog</asp:ListItem>
<asp:ListItem>Connect</asp:ListItem>
</asp:DropDownList>
</div>
<asp:WebPartZone ID="WebPartZone1" runat="server" BorderColor="#CCCCCC" Font-Names="Verdana" Padding="6">
<ZoneTemplate>
</ZoneTemplate>
<PartChromeStyle BackColor="#F7F6F3" BorderColor="#E2DED6" Font-Names="Verdana" ForeColor="White" />
<MenuLabelHoverStyle ForeColor="#E2DED6" />
<EmptyZoneTextStyle Font-Size="0.8em" />
<MenuLabelStyle ForeColor="White" />
<MenuVerbHoverStyle BackColor="#F7F6F3" BorderColor="#CCCCCC" BorderStyle="Solid"
BorderWidth="1px" ForeColor="#333333" />
<HeaderStyle Font-Size="0.7em" ForeColor="#CCCCCC" HorizontalAlign="Center" />
<MenuVerbStyle BorderColor="#5D7B9D" BorderStyle="Solid" BorderWidth="1px" ForeColor="White" />
<PartStyle Font-Size="0.8em" ForeColor="#333333" />
<TitleBarVerbStyle Font-Size="0.6em" Font-Underline="False" ForeColor="White" />
<MenuPopupStyle BackColor="#5D7B9D" BorderColor="#CCCCCC" BorderWidth="1px" Font-Names="Verdana"
Font-Size="0.6em" />
<PartTitleStyle BackColor="#5D7B9D" Font-Bold="True" Font-Size="0.8em" ForeColor="White" />
</asp:WebPartZone>
<asp:WebPartZone ID="WebPartZone2" runat="server" BorderColor="#CCCCCC" Font-Names="Verdana" Padding="6">
<PartChromeStyle BackColor="#F7F6F3" BorderColor="#E2DED6" Font-Names="Verdana" ForeColor="White" />
<MenuLabelHoverStyle ForeColor="#E2DED6" />
<EmptyZoneTextStyle Font-Size="0.8em" />
<MenuLabelStyle ForeColor="White" />
<MenuVerbHoverStyle BackColor="#F7F6F3" BorderColor="#CCCCCC" BorderStyle="Solid"
BorderWidth="1px" ForeColor="#333333" />
<HeaderStyle Font-Size="0.7em" ForeColor="#CCCCCC" HorizontalAlign="Center" />
<ZoneTemplate>
<asp:Calendar ID="Calendar1" runat="server" BackColor="#FFFFCC" BorderColor="#FFCC66"
BorderWidth="1px" DayNameFormat="Shortest" Font-Names="Verdana" Font-Size="8pt"
ForeColor="#663399" Height="200px" ShowGridLines="True" Width="220px">
<SelectedDayStyle BackColor="#CCCCFF" Font-Bold="True" />
<TodayDayStyle BackColor="#FFCC66" ForeColor="White" />
<SelectorStyle BackColor="#FFCC66" />
<OtherMonthDayStyle ForeColor="#CC9966" />
<NextPrevStyle Font-Size="9pt" ForeColor="#FFFFCC" />
<DayHeaderStyle BackColor="#FFCC66" Font-Bold="True" Height="1px" />
<TitleStyle BackColor="#990000" Font-Bold="True" Font-Size="9pt" ForeColor="#FFFFCC" />
</asp:Calendar>
</ZoneTemplate>
<MenuVerbStyle BorderColor="#5D7B9D" BorderStyle="Solid" BorderWidth="1px" ForeColor="White" />
<PartStyle Font-Size="0.8em" ForeColor="#333333" />
<TitleBarVerbStyle Font-Size="0.6em" Font-Underline="False" ForeColor="White" />
<MenuPopupStyle BackColor="#5D7B9D" BorderColor="#CCCCCC" BorderWidth="1px" Font-Names="Verdana"
Font-Size="0.6em" />
<PartTitleStyle BackColor="#5D7B9D" Font-Bold="True" Font-Size="0.8em" ForeColor="White" />
</asp:WebPartZone>
<asp:EditorZone ID="EditorZone1" runat="server" BackColor="#F7F6F3" BorderColor="#CCCCCC"
BorderWidth="1px" Font-Names="Verdana" Padding="6">
<HeaderStyle BackColor="#E2DED6" Font-Bold="True" Font-Size="0.8em" ForeColor="#333333" />
<LabelStyle Font-Size="0.8em" ForeColor="#333333" />
<HeaderVerbStyle Font-Bold="False" Font-Size="0.8em" Font-Underline="False" ForeColor="#333333" />
<PartChromeStyle BorderColor="#E2DED6" BorderStyle="Solid" BorderWidth="1px" />
<PartStyle BorderColor="#F7F6F3" BorderWidth="5px" />
<FooterStyle BackColor="#E2DED6" HorizontalAlign="Right" />
<EditUIStyle Font-Names="Verdana" Font-Size="0.8em" ForeColor="#333333" />
<InstructionTextStyle Font-Size="0.8em" ForeColor="#333333" />
<ErrorStyle Font-Size="0.8em" />
<VerbStyle Font-Names="Verdana" Font-Size="0.8em" ForeColor="#333333" />
<EmptyZoneTextStyle Font-Size="0.8em" ForeColor="#333333" />
<PartTitleStyle Font-Bold="True" Font-Size="0.8em" ForeColor="#333333" />
<ZoneTemplate>
<asp:LayoutEditorPart ID="LayoutEditorPart1" runat="server" />
<asp:AppearanceEditorPart ID="AppearanceEditorPart1" runat="server" />
<asp:BehaviorEditorPart ID="BehaviorEditorPart1" runat="server" />
<asp:PropertyGridEditorPart ID="PropertyGridEditorPart1" runat="server" />
</ZoneTemplate>
</asp:EditorZone>
<asp:CatalogZone ID="CatalogZone1" runat="server" BackColor="#F7F6F3" BorderColor="#CCCCCC"
BorderWidth="1px" Font-Names="Verdana" Padding="6">
<HeaderVerbStyle Font-Bold="False" Font-Size="0.8em" Font-Underline="False" ForeColor="#333333" />
<PartTitleStyle BackColor="#5D7B9D" Font-Bold="True" Font-Size="0.8em" ForeColor="White" />
<PartChromeStyle BorderColor="#E2DED6" BorderStyle="Solid" BorderWidth="1px" />
<InstructionTextStyle Font-Size="0.8em" ForeColor="#333333" />
<PartLinkStyle Font-Size="0.8em" />
<EmptyZoneTextStyle Font-Size="0.8em" ForeColor="#333333" />
<LabelStyle Font-Size="0.8em" ForeColor="#333333" />
<VerbStyle Font-Names="Verdana" Font-Size="0.8em" ForeColor="#333333" />
<ZoneTemplate>
<asp:PageCatalogPart ID="PageCatalogPart1" runat="server" />
<asp:DeclarativeCatalogPart ID="DeclarativeCatalogPart1" runat="server">
<WebPartsTemplate>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
</WebPartsTemplate>
</asp:DeclarativeCatalogPart>
</ZoneTemplate>
<PartStyle BorderColor="#F7F6F3" BorderWidth="5px" />
<SelectedPartLinkStyle Font-Size="0.8em" />
<FooterStyle BackColor="#E2DED6" HorizontalAlign="Right" />
<HeaderStyle BackColor="#E2DED6" Font-Bold="True" Font-Size="0.8em" ForeColor="#333333" />
<EditUIStyle Font-Names="Verdana" Font-Size="0.8em" ForeColor="#333333" />
</asp:CatalogZone>
</form>
</body>
</html>
还有这个:
Default.aspx.cs
protected void Page_Load(object sender, EventArgs e)
{
if (Portal.Integration.CommonLogin.PageBase.CurrentUser.IsGuest)
{
this.DropDownList1.SelectedValue = "Browse";
this.DropDownList1.Enabled = false;
this.WebPartManager1.DisplayMode = WebPartManager.BrowseDisplayMode;
}
else
{
System.Web.HttpCookie aspCookie
= Request.Cookies[System.Web.Security.FormsAuthentication.FormsCookieName];
if (aspCookie == null)
{
FormsAuthenticationTicket ticket
= new FormsAuthenticationTicket(1,
Portal.Integration.CommonLogin.PageBase.CurrentUser.Username.ToString(),
DateTime.Now,
DateTime.Now.AddDays(1),
false,
Portal.Integration.CommonLogin.PageBase.CurrentUser.Username.ToString());
string encryptedTicket = FormsAuthentication.Encrypt(ticket);
aspCookie = new HttpCookie(FormsAuthentication.FormsCookieName,
encryptedTicket);
Response.Cookies.Add(aspCookie);
Response.Redirect(Request.RawUrl);
}
}
}
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
if (DropDownList1.SelectedValue == "Design")
{
this.WebPartManager1.DisplayMode = WebPartManager.DesignDisplayMode;
}
else if (DropDownList1.SelectedValue == "Edit")
{
this.WebPartManager1.DisplayMode = WebPartManager.EditDisplayMode;
}
else if (DropDownList1.SelectedValue == "Catalog")
{
this.WebPartManager1.DisplayMode = WebPartManager.CatalogDisplayMode;
}
//else if (DropDownList1.SelectedValue == "Connect")
//{
// this.WebPartManager1.DisplayMode = WebPartManager.ConnectDisplayMode;
//}
else
{
this.WebPartManager1.DisplayMode = WebPartManager.BrowseDisplayMode;
}
}
protected void Page_Load(object sender, EventArgs e)
{
if (Portal.Integration.CommonLogin.PageBase.CurrentUser.IsGuest)
{
this.DropDownList1.SelectedValue = "Browse";
this.DropDownList1.Enabled = false;
this.WebPartManager1.DisplayMode = WebPartManager.BrowseDisplayMode;
}
else
{
System.Web.HttpCookie aspCookie
= Request.Cookies[System.Web.Security.FormsAuthentication.FormsCookieName];
if (aspCookie == null)
{
FormsAuthenticationTicket ticket
= new FormsAuthenticationTicket(1,
Portal.Integration.CommonLogin.PageBase.CurrentUser.Username.ToString(),
DateTime.Now,
DateTime.Now.AddDays(1),
false,
Portal.Integration.CommonLogin.PageBase.CurrentUser.Username.ToString());
string encryptedTicket = FormsAuthentication.Encrypt(ticket);
aspCookie = new HttpCookie(FormsAuthentication.FormsCookieName,
encryptedTicket);
Response.Cookies.Add(aspCookie);
Response.Redirect(Request.RawUrl);
}
}
}
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
if (DropDownList1.SelectedValue == "Design")
{
this.WebPartManager1.DisplayMode = WebPartManager.DesignDisplayMode;
}
else if (DropDownList1.SelectedValue == "Edit")
{
this.WebPartManager1.DisplayMode = WebPartManager.EditDisplayMode;
}
else if (DropDownList1.SelectedValue == "Catalog")
{
this.WebPartManager1.DisplayMode = WebPartManager.CatalogDisplayMode;
}
//else if (DropDownList1.SelectedValue == "Connect")
//{
// this.WebPartManager1.DisplayMode = WebPartManager.ConnectDisplayMode;
//}
else
{
this.WebPartManager1.DisplayMode = WebPartManager.BrowseDisplayMode;
}
}
这样就完了,还是很简单的,以后可以参考啦。。。