SharePoint 2010 Hides the login link in sites that allow anonymous access

Source: Internet
Author: User

SharePoint 2010 Hides a login link in a Web site that allows anonymous access recently, when using the Welcome.ascx user control, many things are found to be rendered by it.        Here, for example, the hidden login link for anonymous access users in the site is also related to it. It takes about two steps to complete such a function. Very simple. You need to use the master page and the SharePoint Application page link control. 1. Copy the Welcome.ascx control and name Customwelcome.ascx. Overwrite the OnLoad event to hide the login Application page link for anonymous users.        2. Refer to the custom Customwelcome.ascx in the master page. In C:\Program files\common files\microsoft Shared\Web Server Extensions\14\template\ ControlTemplates you will find the Welcome.ascx file, copy and open the Customwelcome.ascx file. You will see that for authenticated users, many menu items such as my settings, logging in as other users, logging off, etc. are available. All menu items are available under ID "Explicitlogout". As you can see, the Personal actions control is not visible when the user is successfully validated.
<%@ Register tagprefix= "SharePoint" namespace= "Microsoft.SharePoint.WebControls" assembly= "Microsoft.SharePoint , version=, Culture=neutral, publickeytoken=71e9bce111e9429c "%> <%@ Register tagprefix=" Utilities " Namespace= "Microsoft.SharePoint.Utilities" assembly= "Microsoft.SharePoint, version=, Culture=neutral, publickeytoken=71e9bce111e9429c "%> <%@ Import namespace=" Microsoft.SharePoint "%> <%@ Assembly Name=" Microsoft.Web.CommandUI, version=, Culture=neutral, publickeytoken=71e9bce111e9429c "%><%@ Control Language= "C #" inherits= "microsoft.sharepoint.webcontrols.welcome,microsoft.sharepoint,version=,culture= neutral,publickeytoken=71e9bce111e9429c "autoeventwireup=" false "compilationmode=" Always "%> <SharePoint: Personalactions accesskey= "<% $Resources:wss,personalactions_menu_ak%>" tooltip= "<% $Resources: Wss,open_ Menu%> "runat=" Server "id=" Explicitlogout "visible=" false "><CustomTemplate> <sharepoInt:featuremenutemplate runat= "Server" featurescope= "Site" location= "Microsoft.SharePoint.StandardMenu" groupid= " Personalactions "id=" Id_personalactionmenu "useshortid=" true "> <sharepoint:menuitemtemplate runat=" server "ID = "Id_personalinformation" text= "<% $Resources:wss,personalactions_personalinformation%>" Description= "<% $Resources:wss,personalactions_personalinformationdescription%> "menugroupid=" sequence= "ImageUrl="/_ Layouts/images/menuprofile.gif "useshortid=" true "/> <sharepoint:menuitemtemplate runat=" Server "id=" ID_ Loginasdifferentuser "text=" <% $Resources:wss,personalactions_loginasdifferentuser%> "Description=" <%$ Resources:wss,personalactions_loginasdifferentuserdescription%> "menugroupid=", "Sequence=", "UseShortId=" True "/> <sharepoint:menuitemtemplate runat=" Server "id=" id_requestaccess "text=" <% $Resources: WSS, Personalactions_requestaccess%> "description=" <% $Resources: Wss,personalactions_requestaccessdescriptIon%> "menugroupid=" "useshortid=" true "sequence=" "/> <sharepoint:menuitemtemplate" "Server" runat= "Id_logout" text= "<% $Resources:wss,personalactions_logout%>" description= "<% $Resources: WSS, Personalactions_logoutdescription%> "menugroupid=" "sequence=" "useshortid=" true "/> <SharePoint: Menuitemtemplate runat= "Server" id= "Id_personalizepage" text= "<% $Resources: Wss,personalactions_personalizepage %> "description=" <% $Resources:wss,personalactions_personalizepagedescription%> "Imageurl="/_layouts/ Images/menupersonalize.gif "clientonclickscript=" Javascript:changelayoutmode (true); " permissionsstring= "Adddelprivatewebparts,updatepersonalwebparts" permissionmode= "any" MenuGroupId= "Sequence=" "Useshortid=" "true"/> <sharepoint:menuitemtemplate runat= "Server" id= "Id_switchview" menugroupid= "300" Sequence= "useshortid=" "true"/> <sharepoint:menuitemtemplate runat= "Server" id= "Msomenu_restoredefaults" text= "<% $Resources:Wss,personalactions_restorepagedefaults%> "description=" <% $Resources: Wss,personalactions_ Restorepagedefaultsdescription%> "Clientonclicknavigateurl=" JAVASCRIPT:SP. Sod.execute (' Browserscript ', ' Msowebpartpage_restorepagedefault ') "menugroupid=" "sequence=" UseShortId= " True "/> </SharePoint:FeatureMenuTemplate></CustomTemplate></SharePoint:PersonalActions>
The other part is the user control Explicitlogin as a SharePoint application Page link.
<sharepoint:applicationpagelink runat= "Server" id= "Explicitlogin" applicationpagefilename= "Authenticate.aspx" appendcurrentpageurl=truetext= "<% $Resources:wss,login_pagetitle%>" style= "Display:none" Visible= "false"/ >
This link we need to look into. default is not visible; appears when the user is not authenticated. That's what anonymous users see.        So they can land. We add a script to the Customwelcome.ascx control, overwrite the OnLoad event, and hide the explicitlogin link for non-authenticated users.
protected override void OnLoad (EventArgs e)    {        //base. OnLoad (e);        Base. OnLoad (e);        if (HttpContext.Current.User.Identity.IsAuthenticated)        {this            . Explicitlogout.visible = true;        }        Else        {this            . Explicitlogin.visible = false;            This. EXPLICITLOGIN.ATTRIBUTES.CSSSTYLE.ADD ("Display", "block");        }     }
This custom customwelcome.ascx file is referenced in the master page.
<%@ Register tagprefix= "wssuc" tagname= "Customwelcome" src= "~/_controltemplates/customwelcome.ascx"%>
Save. Re-enter the site, you will see that for unauthenticated users, the login link has not been seen.
But I found that the tab in the upper left corner was abnormal.
Locate the statement in the master page:
<wssuc:welcome id= "Idwelcome" runat= "Server" enableviewstate= "false" ></wssuc:Welcome>
After adding visible= "False", refresh the first page. Back to normal.

If you understand the Welcome.ascx file and its structure, you will find that customization becomes easy and fun.
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.