title: ASP.NET login form authentication without login control
body: <p>I am using ASP.NET membership and on registration page trying to login without a login control.</p>
  
  <p>When user clicks on the register button, the control goes to redirect.aspx page.
  But in that page, while I am trying to redirect to the members homepage its throwing the following error.</p>
  
  <p>ERROR -</p>
  
  <pre><code>Unable to evaluate expression because the code is optimized or a native frame
  is on top of the call stack.
  </code></pre>
  
  <p>Web.config -</p>
  
  <pre><code>&lt;authentication mode="Forms"&gt;
      &lt;forms name=".SSOAuth" loginUrl="login.aspx" defaultUrl="Redirect.aspx"
             protection="Validation" timeout="30000"/&gt;
  &lt;/authentication&gt;
  </code></pre>
  
  <p>RegistrationPage code - </p>
  
  <pre><code>protected void btnRegister_Click(object sender, EventArgs e)
  {
      MembershipUser userMemb = Membership.CreateUser(
                             txtemail.Text.Replace("'", "''").ToString(),
                             txtPassword.Text.Replace("'", "''").ToString(),
                             txtemail.Text.ToString());
  
      Roles.AddUserToRole(txtemail.Text.ToString(), "Member");
      FormsAuthentication.RedirectFromLoginPage(txtemail.Text.Trim(), false);
  }
  </code></pre>
  
  <p>Redirect.aspx.cs code -</p>
  
  <pre><code>try
  {
      if (User.IsInRole("Member"))
      {
          string UserName = User.Identity.Name;                        
          Response.Redirect("~/Member/MembeHome.aspx");
      }
  }
  catch(Exception ex) {}
  </code></pre>