title: ASP.Net: Password protected pages to allow access bots
body: <p>I have an asp.net webforms page which is allowed to user after logging in with username and password. Currently when an user shares a page, the login page will be fetched by facebook's sharer.php file.</p>
  
  <p>below is my code in page load.</p>
  
  <pre><code>string fbUA = HttpContext.Current.Request.UserAgent;
  
              if (RouteData.Values["NewsId"] != null)
              {
                  if (fbUA.Contains("FacebookExternalHit") || fbUA.Contains("Googlebot"))
                  {
                      int qryStr = int.Parse(RouteData.Values["NewsId"] as string);
                      BindSingleNews(qryStr);
                      BindRelatesNews(qryStr);
                      HandleLoginMenu();
                  }
                  else
                  {
                      if (Session["UserName"] == null &amp;&amp; Session["UserId"] == null)
                      {
                          RequestLogin();
                      }
                      else
                      {
                          int qryStr = int.Parse(RouteData.Values["NewsId"] as string);
                          BindSingleNews(qryStr);
                          BindRelatesNews(qryStr);
                          HandleLoginMenu();
                      }
                  }                 
              }
              else
              {
                  Response.Redirect("/");
              }
  </code></pre>
  
  <p>I have og tags and all. I am using <code>&lt;div id="divFBShare" runat="server" class="fb-share-button" data-layout="button_count"&gt;&lt;/div&gt;</code> and binding <code>data-href</code> to it through codebehind. </p>
  
  <p>How can I allow facebook share, google and bing bots to crawl such pages in webforms? </p>
  
  <hr>
  
  <p><strong>UPDATE</strong>: </p>
  
  <p><code>fbUA.Contains("Googlebot")</code> is working fine. I can fetch such pages as google in Google webmaster tools. However, facebook sharing is still not working. </p>