title: Getting a user name through java script in sharepoint aspx page
body: <p>I am using Microsoft Office 365 (Plan P1). I have a user "ABC". I want that whenever ABC logs in, he is redirected to a specific site let's say Marketing site.</p>
  
  <p>I am writing a javascript code as below:</p>
  
  <pre><code>&lt;script type="text/javascript" language="javascript"&gt;
  
  if(document.getElementById('&lt;%=LoginName1.ClientID %&gt;') == "ABC"; 
  location.href="/teamsite/Home.aspx";
  
  &lt;/script&gt;
  </code></pre>
  
  <p>But I am getting error that code blocks not allowed. Can someone help?</p>
  
  <hr>
  
  <p>Below is the code of page:</p>
  
  <pre><code>&lt;%-- _lcid="1033" _version="14.0.4762" _dal="1" --%&gt;
  &lt;%-- _LocalBinding --%&gt;
  &lt;%@ Page language="C#" MasterPageFile="~masterurl/default.master"    Inherits="Microsoft.SharePoint.WebPartPages.WebPartPage,Microsoft.SharePoint,Version=14.0.0.0,Culture=neutral,PublicKeyToken=71e9bce111e9429c" meta:progid="SharePoint.WebPartPage.Document"  %&gt;
  &lt;%@ Register Tagprefix="SharePoint" Namespace="Microsoft.SharePoint.WebControls" Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %&gt; 
  &lt;%@ Register Tagprefix="Utilities" Namespace="Microsoft.SharePoint.Utilities" Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %&gt; 
  &lt;%@ Import Namespace="Microsoft.SharePoint" %&gt; &lt;%@ Assembly Name="Microsoft.Web.CommandUI, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %&gt; &lt;%@ Register Tagprefix="WebPartPages" Namespace="Microsoft.SharePoint.WebPartPages" Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %&gt;
  &lt;asp:Content ContentPlaceHolderId="PlaceHolderPageTitle" runat="server"&gt;
  &lt;SharePoint:ListItemProperty Property="BaseName" maxlength="40" runat="server"/&gt;
  &lt;/asp:Content&gt;
  &lt;asp:Content ContentPlaceHolderId="PlaceHolderPageTitleInTitleArea" runat="server"&gt;
  &lt;WebPartPages:WebPartZone runat="server" title="loc:TitleBar" id="TitleBar" AllowLayoutChange="false" AllowPersonalization="false"&gt;&lt;ZoneTemplate&gt;
      &lt;WebPartPages:TitleBarWebPart runat="server" AllowEdit="True" AllowConnect="True" ConnectionID="00000000-0000-0000-0000-000000000000" Title="Web Part Page Title Bar" IsIncluded="True" Dir="Default" IsVisible="True" AllowMinimize="False" ExportControlledProperties="True" ZoneID="TitleBar" ID="g_771de8f3_6bde_473c_ade0_fd62f3baa052" HeaderTitle="Calculating..." AllowClose="False" FrameState="Normal" ExportMode="All" AllowRemove="False" AllowHide="True" SuppressWebPartChrome="False" DetailLink="" ChromeType="None" HelpLink="" MissingAssembly="Cannot import this Web Part." PartImageSmall="" HelpMode="Modeless" FrameType="None" AllowZoneChange="True" PartOrder="1" Description="" PartImageLarge="" IsIncludedFilter="" __MarkupType="vsattributemarkup" __WebPartId="{771DE8F3-6BDE-473C-ADE0-FD62F3BAA052}" WebPart="true" Height="" Width=""&gt;&lt;/WebPartPages:TitleBarWebPart&gt;
  
  &lt;WebPartPages:TitleBarWebPart runat="server" AllowEdit="True" AllowConnect="True" ConnectionID="00000000-0000-0000-0000-000000000000" Title="Web Part Page Title Bar" IsIncluded="True" Dir="Default" IsVisible="True" AllowMinimize="False" ExportControlledProperties="True" ZoneID="TitleBar" ID="g_ea882083_ab10_4e70_9986_6cbe1640086a" HeaderTitle="Calculating..." AllowClose="False" FrameState="Normal" ExportMode="All" AllowRemove="False" AllowHide="True" SuppressWebPartChrome="False" DetailLink="" ChromeType="None" HelpLink="" MissingAssembly="Cannot import this Web Part." PartImageSmall="" HelpMode="Modeless" FrameType="None" AllowZoneChange="True" PartOrder="2" Description="" PartImageLarge="" IsIncludedFilter="" __MarkupType="vsattributemarkup" __WebPartId="{EA882083-AB10-4E70-9986-6CBE1640086A}" WebPart="true" Height="" Width=""&gt;&lt;/WebPartPages:TitleBarWebPart&gt;
  
  &lt;/ZoneTemplate&gt;&lt;/WebPartPages:WebPartZone&gt;
  &lt;/asp:Content&gt;
  &lt;asp:Content ContentPlaceHolderId="PlaceHolderTitleAreaClass" runat="server"&gt;
  &lt;style type="text/css"&gt;
  Div.ms-titleareaframe {
  height: 100%;
  }
  .ms-pagetitleareaframe table {
  background: none;
  }
  &lt;/style&gt;
  &lt;/asp:Content&gt;
  &lt;asp:Content ContentPlaceHolderId="PlaceHolderAdditionalPageHead" runat="server"&gt;
  &lt;meta name="GENERATOR" content="Microsoft SharePoint" /&gt;
  &lt;meta name="ProgId" content="SharePoint.WebPartPage.Document" /&gt;
  &lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8" /&gt;
  &lt;meta name="CollaborationServer" content="SharePoint Team Web Site" /&gt;
  &lt;script type="text/javascript"&gt;
  // &lt;![CDATA[
  var navBarHelpOverrideKey = "WSSEndUser";
  // ]]&gt;
  &lt;/script&gt;
  &lt;SharePoint:UIVersionedContent ID="WebPartPageHideQLStyles" UIVersion="4" runat="server"&gt;
      &lt;ContentTemplate&gt;
  &lt;style type="text/css"&gt;
  body #s4-leftpanel {
  display:none;
  }
  .s4-ca {
  margin-left:0px;
  }
  &lt;/style&gt;
      &lt;/ContentTemplate&gt;
  &lt;/SharePoint:UIVersionedContent&gt;
  &lt;/asp:Content&gt;
  &lt;asp:Content ContentPlaceHolderId="PlaceHolderSearchArea" runat="server"&gt;
  &lt;SharePoint:DelegateControl runat="server"
      ControlId="SmallSearchInputBox"/&gt;
  &lt;/asp:Content&gt;
  &lt;asp:Content ContentPlaceHolderId="PlaceHolderLeftActions" runat="server"&gt;
  &lt;/asp:Content&gt;
  &lt;asp:Content ContentPlaceHolderId="PlaceHolderPageDescription" runat="server"&gt;
  &lt;SharePoint:ProjectProperty Property="Description" runat="server"/&gt;
  &lt;/asp:Content&gt;
  &lt;asp:Content ContentPlaceHolderId="PlaceHolderBodyRightMargin" runat="server"&gt;
  &lt;div height="100%" class="ms-pagemargin"&gt;&lt;img src="/_layouts/images/blank.gif" width="10" height="1" alt="" /&gt;&lt;/div&gt;
  &lt;/asp:Content&gt;
  
  &lt;asp:Content ContentPlaceHolderId="PlaceHolderPageImage" runat="server"&gt;&lt;/asp:Content&gt;
  &lt;asp:Content ContentPlaceHolderId="PlaceHolderNavSpacer" runat="server"&gt;&lt;/asp:Content&gt;
  &lt;asp:Content ContentPlaceHolderId="PlaceHolderLeftNavBar" runat="server"&gt;&lt;/asp:Content&gt;
  &lt;asp:Content ContentPlaceHolderId="PlaceHolderMain" runat="server"&gt;
      &lt;table cellpadding="4" cellspacing="0" border="0" width="100%"&gt;
              &lt;tr&gt;
                  &lt;td id="_invisibleIfEmpty" name="_invisibleIfEmpty" valign="top" width="100%"&gt; 
                  &lt;WebPartPages:WebPartZone runat="server" Title="loc:FullPage" ID="FullPage" FrameType="TitleBarOnly"&gt;&lt;ZoneTemplate&gt;&lt;/ZoneTemplate&gt;&lt;/WebPartPages:WebPartZone&gt; &lt;/td&gt;
              &lt;/tr&gt;
              &lt;script type="text/javascript" language="javascript"&gt;if(typeof(MSOLayout_MakeInvisibleIfEmpty) == "function") {MSOLayout_MakeInvisibleIfEmpty();}&lt;/script&gt;
      &lt;/table&gt;
  &lt;/asp:Content&gt;
  
  
  &lt;asp:Content&gt;
  &lt;script type="text/javascript"&gt; 
  ExecuteOrDelayUntilScriptLoaded(getUserData, "sp.js");   
  var context = null; 
  var web = null; 
  var currentUser = null; 
      function getUserData() { 
          context = new SP.ClientContext.get_current(); 
          web = context.get_web(); 
          currentUser = web.get_currentUser(); 
          currentUser.retrieve(); 
          context.load(web); 
          context.executeQueryAsync(Function.createDelegate(this, this.onUserDataSuccess), Function.createDelegate(this, this.onUserDataFailure)); 
      } 
      function onUserDataSuccess(sender, args) { 
          var user = web.get_currentUser(); 
          alert('User name:' + user.get_title() + '\n Login Name:' + userObject.get_loginName()); 
      } 
      function onUserDataFailure(sender, args) { 
          alert('request failed ' + args.get_message() + '\n' + args.get_stackTrace()); 
      } 
  &lt;/script&gt;
  &lt;/asp:Content&gt;`enter code here`
  </code></pre>