title: Not working login with roles (web forms)
body: <p>I want create a authentication module with 3 roles in asp.net web forms.
  I created a simple database with one table user (id, login, password, role).
  I have a 3 roles: user, user2 and admin.
  I would like to users with specific roles were redirected to individual pages.</p>
  
  <p>Login.aspx.cs</p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Web;
  using System.Web.UI;
  using System.Web.UI.WebControls;
  using System.Data.SqlClient;
  using System.Configuration;
  
  namespace WebApplication6
  {
      public partial class Login : System.Web.UI.Page
      {
          static string DatabaseConnectionString = System.Configuration.ConfigurationManager.ConnectionStrings["dbtestConnectionStrings"].ConnectionString;
          SqlConnection _connection= new SqlConnection(DatabaseConnectionString);
  
  
      protected void Page_Load(object sender, EventArgs e) { 
      }
  
      protected void LoginButton_Click(object sender, EventArgs e)
      {
          try
          {
              var comm = new SqlCommand("select * from user where login=@login and password=@password", _connection);
  
              comm.Parameters.AddWithValue("@login", LoginUser.UserName);
              comm.Parameters.AddWithValue("@password", LoginUser.Password);
  
              _connection.Open();
  
              var rd = comm.ExecuteReader(); 
              if (rd.HasRows)
              {
                  while (rd.Read())
                  {
                      Session["UserName"] = rd["login"].ToString();
                      string role = rd["role"].ToString();
                      if (role == "user") Response.Redirect("User/User.aspx");
                      else if (role == "user2") Response.Redirect("User2/User.aspx");
                      else Response.Redirect("Admin/Admin.aspx"); 
                  }
              }
  
              else
              {
                  LoginUser.FailureText = "ERROR";
              }
  
          }
          catch (Exception exception)
          {
              Response.Write(exception.StackTrace);
          }
          }         
      }
  }
  </code></pre>
  
  <p><a href="http://i.stack.imgur.com/fHIzx.png" rel="nofollow">Result:</a></p>
  
  <p>web.config</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;!--
    For more information on how to configure your ASP.NET application, please visit
    http://go.microsoft.com/fwlink/?LinkId=169433
    --&gt;
  &lt;configuration&gt;
    &lt;configSections&gt;
      &lt;!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 --&gt;
      &lt;section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" /&gt;
    &lt;/configSections&gt;
    &lt;system.web&gt;
      &lt;compilation debug="true" targetFramework="4.5.2" /&gt;
      &lt;httpRuntime targetFramework="4.5.2" /&gt;
      &lt;httpModules&gt;
        &lt;add name="ApplicationInsightsWebTracking" type="Microsoft.ApplicationInsights.Web.ApplicationInsightsHttpModule, Microsoft.AI.Web" /&gt;
      &lt;/httpModules&gt;
    &lt;/system.web&gt;
    &lt;system.codedom&gt;
      &lt;compilers&gt;
        &lt;compiler language="c#;cs;csharp" extension=".cs" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:6 /nowarn:1659;1699;1701" /&gt;
        &lt;compiler language="vb;vbs;visualbasic;vbscript" extension=".vb" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.VBCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:14 /nowarn:41008 /define:_MYTYPE=\&amp;quot;Web\&amp;quot; /optionInfer+" /&gt;
      &lt;/compilers&gt;
    &lt;/system.codedom&gt;
    &lt;system.webServer&gt;
      &lt;validation validateIntegratedModeConfiguration="false" /&gt;
      &lt;modules&gt;
        &lt;remove name="ApplicationInsightsWebTracking" /&gt;
        &lt;add name="ApplicationInsightsWebTracking" type="Microsoft.ApplicationInsights.Web.ApplicationInsightsHttpModule, Microsoft.AI.Web" preCondition="managedHandler" /&gt;
      &lt;/modules&gt;
    &lt;/system.webServer&gt;
    &lt;appSettings&gt;
      &lt;add key="ValidationSettings:UnobtrusiveValidationMode" value="None" /&gt;
    &lt;/appSettings&gt;
    &lt;connectionStrings&gt;
      &lt;add name="dbtestEntities" connectionString="metadata=res://*/DataModel.csdl|res://*/DataModel.ssdl|res://*/DataModel.msl;provider=System.Data.SqlClient;provider connection string=&amp;quot;data source=ROG-KOMPUTER\SQLEXPRESS;initial catalog=dbtest;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework&amp;quot;"
        providerName="System.Data.EntityClient" /&gt;
      &lt;add name="dbtestConnectionString" connectionString="Data Source=ROG-KOMPUTER\SQLEXPRESS;Initial Catalog=dbtest;Integrated Security=True;MultipleActiveResultSets=True;Application Name=EntityFramework"
        providerName="System.Data.SqlClient" /&gt;
    &lt;/connectionStrings&gt;
    &lt;entityFramework&gt;
      &lt;defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" /&gt;
      &lt;providers&gt;
        &lt;provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" /&gt;
      &lt;/providers&gt;
    &lt;/entityFramework&gt;
  &lt;/configuration&gt;
  </code></pre>