sharepoint 2010 怎么为cas自定义登录页面的登录页面,增加自动登陆

Sharepoint 2010 自定义列表如何增加一个超链接列
[问题点数:20分,结帖人wang2245]
Sharepoint 2010 自定义列表如何增加一个超链接列
[问题点数:20分,结帖人wang2245]
不显示删除回复
显示所有回复
显示星级回复
显示得分回复
只显示楼主
2015年1月 企业软件大版内专家分月排行榜第一
2015年1月 企业软件大版内专家分月排行榜第一
2015年1月 企业软件大版内专家分月排行榜第一
2014年4月 荣获微软MVP称号
2014年12月 企业软件大版内专家分月排行榜第一2014年11月 企业软件大版内专家分月排行榜第一2014年7月 企业软件大版内专家分月排行榜第一2011年10月 企业开发大版内专家分月排行榜第一2011年5月 企业开发大版内专家分月排行榜第一2011年3月 企业开发大版内专家分月排行榜第一2010年12月 企业开发大版内专家分月排行榜第一2010年11月 企业开发大版内专家分月排行榜第一2010年9月 企业开发大版内专家分月排行榜第一2010年8月 企业开发大版内专家分月排行榜第一2010年7月 企业开发大版内专家分月排行榜第一2010年6月 企业开发大版内专家分月排行榜第一2010年5月 企业开发大版内专家分月排行榜第一
2014年4月 荣获微软MVP称号
2014年12月 企业软件大版内专家分月排行榜第一2014年11月 企业软件大版内专家分月排行榜第一2014年7月 企业软件大版内专家分月排行榜第一2011年10月 企业开发大版内专家分月排行榜第一2011年5月 企业开发大版内专家分月排行榜第一2011年3月 企业开发大版内专家分月排行榜第一2010年12月 企业开发大版内专家分月排行榜第一2010年11月 企业开发大版内专家分月排行榜第一2010年9月 企业开发大版内专家分月排行榜第一2010年8月 企业开发大版内专家分月排行榜第一2010年7月 企业开发大版内专家分月排行榜第一2010年6月 企业开发大版内专家分月排行榜第一2010年5月 企业开发大版内专家分月排行榜第一
匿名用户不能发表回复!|
每天回帖即可获得10分可用分!小技巧:
你还可以输入10000个字符
(Ctrl+Enter)
请遵守CSDN,不得违反国家法律法规。
转载文章请注明出自“CSDN(www.csdn.net)”。如是商业用途请联系原作者。为SharePoint 2010中的FBA创建自定义登录页面SharePoint 2010中默认的FBA登录页面非常简单,只提供了一个Asp.Net的Login控件,让用户输入用户名和密码。在大多数情况下,我们需要定制这个页面以满足一些安全需求,比如为登录页面加上验证码等等。 由于SharePoint 2010里的FBA已经变成了基于Claims认证的方式,因此在实现自定义的登录页面时就与MOSS 2007里的做法完全不同了。最显著的一点就是,像Steve Peschka,以前的FormsAuthentication类不会再被用到了。现在我们需要用SharePoint的STS来做认证和处理Claims。好在SharePoint提供了相应的借口,让这一切变得容易了许多。这这篇文章里,我将演示如何创建自定义登录页面,并保持默认的master page和样式。由于要修改默认页面,我不知道这样的做法是否受Microsoft官方支持,如果你要用在你的项目中,风险自负。
创建自定义登录页面如果我们留意一下会发现,默认的FBA登录页面是_forms/default.aspx。这样的设计有一个好处,就是如果我们修改了default.aspx,它不会影响别的Web app。下面我就在一个default.aspx页面上加了一个验证码功能。
&asp:login id="loginControl"
FailureText="&%$Resources:wss,login_pageFailureText%&"
runat="server" width="100%" OnLoggingIn="signInControl_LoggingIn"
OnAuthenticate="signInControl_Authenticate"& &layouttemplate&
&asp:label id="FailureText" class="ms-error" runat="server"/&
&table width="100%"&
&td nowrap="nowrap"&
&SharePoint:EncodedLiteral runat="server"
text="&%$Resources:wss,login_pageUserName%&"
EncodeMethod='HtmlEncode'/&
&td width="100%"&
&asp:textbox id="UserName"
autocomplete="off"
runat="server"
class="ms-inputuserfield" width="99%" /&
&td nowrap="nowrap"&
&SharePoint:EncodedLiteral runat="server"
text="&%$Resources:wss,login_pagePassword%&"
EncodeMethod='HtmlEncode'/&
&td width="100%"&
&asp:textbox id="password" TextMode="Password"
autocomplete="off" runat="server"
class="ms-inputuserfield" width="99%"/&
&td nowrap="nowrap"&
&SharePoint:EncodedLiteral runat="server"
text="Secure Code:" EncodeMethod='HtmlEncode'/&
&td width="100%"&
&asp:textbox id="secureCode" autocomplete="off"
runat="server" class="ms-inputuserfield" Width="85%" /&
&SharePoint:EncodedLiteral ID="secureCodeLit"
runat="server" Text="1234" EncodeMethod="HtmlEncode" /&
&td colspan="2" align="right"&
&asp:button id="login" commandname="Login"
text="&%$Resources:wss,login_pagetitle%&" runat="server" /&
&td colspan="2"&
&asp:checkbox id="RememberMe"
text="&%$SPHtmlEncodedResources:wss,login_pageRememberMe%&"
runat="server" /&
&/layouttemplate& &/asp:login&
我的想法是,当用户登录的时候,只有输入了正确的用户名密码和验证码,这里是1234,之后才能成功登录。当然,此时验证码还没有作用,我们必须写一些代码来实现验证的功能。
创建Code Behind类实现验证和登录功能接下来是为default.aspx实现一个类来实现验证和登录功能。在项目中添加一个类,可以命名为FormsSignInPage。接着是添加一些引用,首先是Microsoft.SharePoint.dll。由于我们要处理Claims,System.IdentityModel.dll和Microsoft.IdentityModel.dll也是必须的。另外,SharePoint有一个自己的处理Claims的Module,Microsoft.SharePoint.IdentityModel.dll。添加对它的引用时,需要定位到它所在的目录。 我们的类,FormsSignInPage,当然可以从Asp.Net的Page类派生,但是如果我们看一下默认的登录页面,它是派生自IdentityModelSignInPageBase。这个类在Microsoft.SharePoint.IdentityModel.Pages名字空间下,它提供了一些属性和方法,在处理登录时很方便。所以,我决定我的FormsSignInPage也从这个类派生。当用户点击页面上的登录按钮时,有两个Login控件的事件需要处理,一个是LoggingIn,在这个事件中,我们可以处理验证码。另一个是Authenticate,在这个事件中可以实现真正的登录。
protected void signInControl_LoggingIn(objectsender, LoginCancelEventArgs e) {
LoginControl login = sender asLoginC
login.UserName = login.UserName.Trim();
if(string.IsNullOrEmpty(login.UserName))
ClaimsFormsPageMessage.Text = "The server could not sign you in. The user name cannot be empty.";
e.Cancel = true;
if(string.IsNullOrEmpty(secureCode.Text) ||
!string.Equals(secureCode.Text.ToLower(), secureCodeLit.Text.ToLower()))
ClaimsFormsPageMessage.Text = "The server could not sign you in. Please input correct secure code.";
e.Cancel = true;
} }private void EstablishSessionWithToken(SecurityToken securityToken) {
if (null == securityToken)
throw new ArgumentNullException("securityToken");
SPFederationAuthenticationModule fam = SPFederationAuthenticationModule.C
if (null == fam)
throw new ArgumentException(null, "FederationAuthenticationModule");
fam.SetPrincipalAndWriteSessionToken(securityToken); } protected void signInControl_Authenticate(object sender, AuthenticateEventArgs e) {
SecurityToken token = null;
LoginControl formsLoginControl = sender as LoginC
if (null != (token = GetSecurityToken(formsLoginControl)))
EstablishSessionWithToken(token);
e.Authenticated = true;
base.RedirectToSuccessUrl();
} }private SPIisSettings IisSettings {
SPWebApplication webApp = SPWebApplication.Lookup(new Uri(SPContext.Current.Web.Url));SPIisSettings settings = webApp.IisSettings[SPUrlZone.Default];
} } private SecurityToken GetSecurityToken(LoginControl formsLoginControl) {
SecurityToken token = null;
SPIisSettings iisSettings = IisS
Uri appliesTo = base.AppliesTo;
if (string.IsNullOrEmpty(formsLoginControl.UserName) ||
string.IsNullOrEmpty(formsLoginControl.Password))
return null;
SPFormsAuthenticationProvider authProvider = iisSettings.FormsClaimsAuthenticationP
token = SPSecurityContext.SecurityTokenForFormsAuthentication(
appliesTo,
authProvider.MembershipProvider,
authProvider.RoleProvider,
formsLoginControl.UserName,
formsLoginControl.Password);
代码的核心部分是执行登录的部分。SharePoint提供了SecurityTokenForFormsAuthentication专门供开发者处理Forms验证。我使用了SPIisSettings来取得当前Web App所使用的membership provider和roleship provider
SPFormsAuthenticationProvider authProvider = iisSettings.FormsClaimsAuthenticationP token = SPSecurityContext.SecurityTokenForFormsAuthentication(
appliesTo,
authProvider.MembershipProvider,
authProvider.RoleProvider,
formsLoginControl.UserName,
formsLoginControl.Password);
关联Default.aspx和FormsSignInPage这部分比较简单,只要修改&%@ Page %&使它继承我们的FormsSignInPage就好了。
&%@PageLanguage="C#"AutoEventWireup="true"
Inherits="Morpheus.Demo.Pages.FormsSignInPage,FormsSignInPage, Version=1.0.0.0, Culture=neutral, PublicKeyToken=72d2bbe72853b8eb"
MasterPageFile="~/_layouts/simple.master"%&
然后我们就可以将我们的Assembly部署到GAC中,同时将default.aspx拷贝到_forms目录里。当执行登录时,如果用户没有输入正确的验证码,会显示出错误来。转自:
阅读(...) 评论()接前一篇博客《》,当实现混合模式登陆后,接着我们就应该自定义SignIn Page。因为默认的登陆页面实在是太丑了。
当为SharePoint 2013 WebApplication配置了以混合模式(FBA Authentication和Windows Authentication)登陆后,我们当然可以自定义登陆页面(Sign in Page)。登陆SharePoint 2013 Central Administratio后,找到对应的WebApplication,指定其Sign in Page Url即可,如下所示:
创建自定义登陆页面
首先,为了创建自定义的登陆页,我选择了Application Page,默认将被部署在layouts并和项目名称相同的文件夹中(C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\15\template\layouts)。
接着,为了阻止母版页对Application Page的影响,故须去掉母版页的引用,即 DynamicMasterPageFile="~masterurl/default.master"
由于去掉了对母版页的引用,故用于"填坑"控件〈asp:Content/&控件也用不着了,所以整个Application Page将被重新设计。
基于表单验证(FBA )的登陆控件选择了ASP.NET Login控件,设置其相关属性即可。以常见的属性为例:
FailureText:登陆失败时提示的消息
MembershipProvider:自定义的Membership Provider,需要继承MembershipProvider,详见《》
DisplayRememberMe:Bool类型,表示是否显示记住我
RememberMeSet:表示是否向用户浏览器发送持久化已认证的Cookie,默认是False
TextLayout:有2种选择,TextOnLeft(Label在TextBox左),TextOnTop(Label在TextBox上)
UserNameLabelText:用户名Label显示文字
PasswordLabelText:密码Label显示文字
LoginButtonType:有3种选择,Image ,Button,Image
LoginButtonImageUrl:若LoginButtonType选择了Image,此属性表示Image地址
&完整的Login Control代码如下所示:
&asp:Login
ID="signInControl"
style="width: 250px"
FailureText="用户名或密码错误"
MembershipProvider="CustomFBA_Membership"
runat="server"
DisplayRememberMe="true"
TextBoxStyle-Width="250px"
RememberMeSet="true"
UserNameLabelText="用户名"
TextLayout="TextOnLeft"
PasswordLabelText="密码"
LabelStyle-Font-Bold="false"
LabelStyle-Font-Size="Large"
LabelStyle-ForeColor="red"
LabelStyle-Font-Names="宋体"
CheckBoxStyle-Font-Bold="false"
CheckBoxStyle-Font-Names="宋体"
CheckBoxStyle-ForeColor="White"
CheckBoxStyle-Font-Size="Large"
FailureTextStyle-Wrap="true"
FailureTextStyle-Font-Names="宋体"
FailureTextStyle-Font-Size="Small"
LoginButtonStyle-Font-Names="宋体"
LoginButtonStyle-Font-Size="Large"
LoginButtonImageUrl="/_layouts/images/loginbtn.png"
LoginButtonType="Image"
TitleText="登陆"
TitleTextStyle-ForeColor="green"
TitleTextStyle-Font-Bold="true"
TitleTextStyle-Wrap="true"
TitleTextStyle-Font-Names="宋体"
TitleTextStyle-Font-Size="Larger" /&
到目前为止基于表单的身份验证登录已经设计好了,但是别忘了,我么还需要Windows身份验证(也就是Acrive Directory Login)的登陆实现。
添加超链接,以实现Windows 身份验证登陆
&asp:LinkButton ID="lbInternalUsers" Text="Active Directory Login" runat="server" Font-Names="宋体" Font-Size="Small" CssClass="ms-standardheader ms-inputformheader" Font-Bold="true" ForeColor="Wheat" OnClick="lbInternalUsers_OnClick" /&
在其Click事件中实现以域账号登陆&
     protected void lbInternalUsers_OnClick(object sender, EventArgs e)
if (null != SPContext.Current && null != SPContext.Current.Site)
SPIisSettings iisSettings = SPContext.Current.Site.WebApplication.IisSettings[SPUrlZone.Default];
if (null != iisSettings && iisSettings.UseWindowsClaimsAuthenticationProvider)
SPAuthenticationProvider provider = iisSettings.WindowsClaimsAuthenticationP
Redirect(provider);
catch (Exception ex)
private void Redirect(SPAuthenticationProvider provider)
string comp = HttpContext.Current.Request.Url.GetComponents(UriComponents.Query, UriFormat.SafeUnescaped);
string url = provider.AuthenticationRedirectionUrl.ToString();
if (provider is SPWindowsAuthenticationProvider)
comp = EnsureUrl(comp, true);
SPUtility.Redirect(url, SPRedirectFlags.Default, this.Context, comp);
//http://skyrim:6050/_windows/default.aspx?ReturnUrl=
private string EnsureUrl(string url, bool urlIsQueryStringOnly)
if (!url.Contains("ReturnUrl="))
if (urlIsQueryStringOnly)
url = url + (string.IsNullOrEmpty(url) ? "" : "&");
url = url + ((url.IndexOf('?') == -1) ? "?" : "&");
url = url + "ReturnUrl=";
修改默认Sign In Page
当自定义的Sign In Page完成后,给WebApplicatio指定其URL即可,如下所示:
测试基于表单的身份验证登陆,以验证其是否正常工作,登陆成功后向客户端发送名为FedAuth的Cookie
测试基于Windows的身份验证登陆,以验证其是否正常工作
对于自定义的ASP.NET Login控件的名称,注意其名字必须是:signInControl,我在次纠结了很久(异常信息,登陆成功后仍然显示身份验证无效,重定向至:/Authenticate.aspx?Source=%2F ,并向客户端发送名为ASPXAUTH 的 Cookie,当客户端浏览器记住这个错误的ASPXAUTH &Cookie后,下一次访问,返回 500 内部错误。清理掉此Cookie后,又恢复正常)。暂时没有时间去Reflect Sharepoint原始的Login 控件,我估计这个默认的Login控件的名字也是:signInControl。还有一些注意点,也把我纠结很久,详见我的附件。
阅读(...) 评论()您的位置 :ITLead >> >> >>
sharepoint 2010 自定义页面布局
编辑:admin
阅读 2851 次
在sharepoint开发中经常遇到&自定义网站栏、内容类型,页面布局和模板页也会遇到,遇到机会就相对比较小。
首先新建一个空的sharepoint项目:
1)创建网站兰:
修改SiteColumns\Elements.xml文件如下:
&?xml version="1.0" encoding="utf-8"?&
&Elements xmlns="/sharepoint/"&
&Field ID="{76C140E1-D827-433B-AD38-257F}"
Name="BenefitProvider"
DisplayName="Provider Name"
Group="Human Resources"
Type="Text"
Required="FALSE"/&
&Field ID="{A9-469C-90BB-C}"
Name="BenefitProviderLogo"
DisplayName="Provder Logo"
Group="Human Resources"
Type="Image"
Required="FALSE"/&
&Field ID="{5F516D92-969C--CFDC}"
Name="BenefitType"
DisplayName="Benefit Category"
Group="Human Resources"
Type="Choice"
Required="FALSE"&
&CHOICE&Medical&/CHOICE&
&CHOICE&Dental&/CHOICE&
&CHOICE&Vision&/CHOICE&
&CHOICE&Insurance&/CHOICE&
&/CHOICES&
&Field ID="{521D5F12-16BC-4E82-997C-F28933ABE59E}"
Name="BenefitDescription"
DisplayName="Benefit Description"
Group="Human Resources"
Type="HTML" RichText="TRUE" RichTextMode="FullHtml"
Required="FALSE"/&
&/Elements&
2)创建内容内型
修改ContentTypes\Elements.xml文件如下:
&?xml version="1.0" encoding="utf-8"?&
&Elements xmlns="/sharepoint/"&
&!-- Parent ContentType: 文章页面 (0xDB52D9D0A14D9B2FDCCDBEFB8BC526CD44D) --&
&ContentType ID="0xDB52D9D0A14D9B2FDCCDBEFB8BC526CD44Ddd"
Name="Benefits Information Page"
Group="Human Resources"
Description="Benefits Information page layout content type"
Inherits="TRUE"
Version="0"&
&FieldRefs&
&FieldRef ID="{76C140E1-D827-433B-AD38-257F}" Name="BenefitProvider"/&
&FieldRef ID="{A9-469C-90BB-C}" Name="BenefitProviderLogo"/&
&FieldRef ID="{5F516D92-969C--CFDC}" Name="BenefitType"/&
&FieldRef ID="{521D5F12-16BC-4E82-997C-F28933ABE59E}" Name="BenefitDescription"/&
&/FieldRefs&
&/ContentType&
&/Elements&
注意这里的&FieldRef&ID="{76C140E1-D827-433B-AD38-257F}"&Name="BenefitProvider"/&是刚才创建网站栏的ID。
3)创建自定义&页面布局
我这里推荐大家在sharepoint&Designer把页面布局的内容创建好,然后再用feature在部署。
在sharepoint&Designe中:
在用sharepoint&designer导出改文件
把那个文本文件从命名为BenefitsInformation.aspx,把先前sharepoint&designer导出文件的内容拷贝到这个文件上来。
&%@ Page language="C#"
Inherits="Microsoft.SharePoint.Publishing.PublishingLayoutPage,Microsoft.SharePoint.Publishing,Version=14.0.0.0,Culture=neutral,PublicKeyToken=71e9bce111e9429c" meta:webpartpageexpansion="full" meta:progid="SharePoint.WebPartPage.Document" %&
&%@ Register Tagprefix="SharePointWebControls" Namespace="Microsoft.SharePoint.WebControls" Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %&
&%@ Register Tagprefix="WebPartPages" Namespace="Microsoft.SharePoint.WebPartPages" Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %&
&%@ Register Tagprefix="PublishingWebControls" Namespace="Microsoft.SharePoint.Publishing.WebControls" Assembly="Microsoft.SharePoint.Publishing, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %&
&%@ Register Tagprefix="PublishingNavigation" Namespace="Microsoft.SharePoint.Publishing.Navigation" Assembly="Microsoft.SharePoint.Publishing, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %&
&asp:Content ContentPlaceholderID="PlaceHolderPageTitle" runat="server"&
&SharePointWebControls:FieldValue id="PageTitle" FieldName="Title" runat="server"/&
&/asp:Content&
&asp:Content ContentPlaceholderID="PlaceHolderMain" runat="server"&
&SharePointWebControls:TextField FieldName="76c140e1-d827-433b-ad38-257f" runat="server"&&/SharePointWebControls:TextField&
&PublishingWebControls:RichImageField FieldName="a9-469c-90bb-c" runat="server"&&/PublishingWebControls:RichImageField&
&SharePointWebControls:DropDownChoiceField FieldName="5f516d92-969c--cfdc" runat="server"&&/SharePointWebControls:DropDownChoiceField&
&PublishingWebControls:RichHtmlField FieldName="521d5f12-16bc-4e82-997c-f28933abe59e" runat="server"&&/PublishingWebControls:RichHtmlField&
&/asp:Content&
修改BenefitsLayout\Elements.xml&文件:
&?xml version="1.0" encoding="utf-8"?&
&Elements xmlns="/sharepoint/"&
&Module Name="BenefitsLayout"
Url="_catalogs/masterpage" RootWebOnly="TRUE"&
&File Path="BenefitsLayout\BenefitsInformation.aspx" Url="BenefitsInformation.aspx" Type="GhostableInLibrary"&
&Property Name="Title" Value="Benefits Information Page" /&
&Property Name="MasterPageDescription" Value="Use benefits page to publish content related to benefits information" /&
&Property Name="ContentType" Value="$Resources:cmscore,contenttype_pagelayout_" /&
&Property Name="PublishingAssociatedContentType" Value=";#Benefits Information P#0xDB52D9D0A14D9B2FDCCDBEFB8BC526CD44Ddd;#" /&
&/Elements&
注意这里的&&&&Property&Name="PublishingAssociatedContentType"&Value=";#Benefits&Information&P#0xDB52D9D0A14D9B2FDCCDBEFB8BC526CD44Ddd;#"&/&中间这一长串就是我们先前定义的内容类型的ID。
最后发布,发布结果如下:
内容类型:
自定义页面布局:
用我们自己的页面布局来创建一个页面
编辑信息如下:
最后签入:
广州地址:广州天河区翰景路3号金星大厦18楼ABC
深圳地址:深圳市福田区深南中路2018号兴华大厦东座7楼759
联系电话:020- |
粤ICP备号-2

我要回帖

更多关于 sharepoint页面 的文章

 

随机推荐