Click here to Skip to main content
15,887,333 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am using Formsauthentication for login in my small application. It works fine on my local machine but when i upload this on cloud hosting it gives error 'Your login attempt was not successful. Please try again.' message.

my login.aspx.cs file include following code

C#
protected void Page_Load(object sender, EventArgs e)
        {
            if (!this.IsPostBack)
            {
                if (this.Page.User.Identity.IsAuthenticated)
                {
                    FormsAuthentication.SignOut();
                    Response.Redirect("~/Login.aspx");
                }
            }
        }

        protected void ValidateUser(object sender, EventArgs e)
        {
            try
            {
                int userId = 0;
                string roles = string.Empty;
                string constr = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
                using (SqlConnection con = new SqlConnection(constr))
                {
                    using (SqlCommand cmd = new SqlCommand("Validate_User"))
                    {
                        cmd.CommandType = CommandType.StoredProcedure;
                        cmd.Parameters.AddWithValue("@Username", Login1.UserName);
                        cmd.Parameters.AddWithValue("@Password", Login1.Password);
                        cmd.Connection = con;
                        con.Open();
                        SqlDataReader reader = cmd.ExecuteReader();
                        reader.Read();
                        userId = Convert.ToInt32(reader["UserId"]);
                        roles = reader["Roles"].ToString();
                        con.Close();
                    }
                    switch (userId)
                    {
                        case -1:
                            Login1.FailureText = "Username and/or password is incorrect.";
                            break;
                        case -2:
                            Login1.FailureText = "Account has not been activated.";
                            break;
                        default:
                            FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(1, Login1.UserName, DateTime.Now, DateTime.Now.AddMinutes(2880), Login1.RememberMeSet, roles, FormsAuthentication.FormsCookiePath);
                            string hash = FormsAuthentication.Encrypt(ticket);
                            HttpCookie cookie = new HttpCookie(FormsAuthentication.FormsCookieName, hash);

                            if (ticket.IsPersistent)
                            {
                                cookie.Expires = ticket.Expiration;
                            }
                            Response.Cookies.Add(cookie);
                            Response.Redirect(FormsAuthentication.GetRedirectUrl(Login1.UserName, Login1.RememberMeSet));
                            break;
                    }
                }
            }
            catch (Exception ex)
            {
                lblError.Text = "Ehh.. Enter correct password..";
            }
        }


and my web.config file having code

HTML
<configuration>
  <configSections>
    <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=4.4.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
  </configSections>
  <connectionStrings>
    <add name="constr" connectionString="Data Source=IP Address;Initial Catalog=DatabaseName;user id=Username;password=PWD;" />
    <add name="ECOLLEGEMastersEntities" connectionString="metadata=res://*/MastersDataModel1.csdl|res://*/MastersDataModel1.ssdl|res://*/MastersDataModel1.msl;provider=System.Data.SqlClient;provider connection string="data source=IP Address;initial catalog=DatabaseName;persist security info=True;user id=Username;password=password;MultipleActiveResultSets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />
  </connectionStrings>
  <system.web>
    <machineKey validationKey="24389C4FE31C25B571C6E93CBAD77C8487C66B37FF1E972D392BCC7C58A1412791CD25CA0CC8922E6F88A6B20529F26F0C3743F82E902D7C9C9BBF536B2B02C2" 
                decryptionKey="05F5BCA7FF367A1C7EC9C2E5CF898B37E445810ACB0F4E3125144321C733E93C" validation="SHA1" decryption="AES" />
    <customErrors mode="Off" />
    <compilation debug="true" targetFramework="4.5">
      <assemblies>
        <add assembly="System.Data.Entity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
        <add assembly="System.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A" />
        <add assembly="System.Web.Extensions.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
        <add assembly="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" />
      </assemblies>
    </compilation>
    <authentication mode="Forms">
      <forms defaultUrl="~/Home.aspx" loginUrl="~/Login.aspx" slidingExpiration="true" timeout="2880" />
    </authentication>
    <authorization>
      <deny users="?" />
    </authorization>
    <siteMap enabled="true" defaultProvider="SiteMap">
      <providers>
        <add name="SiteMap" type="System.Web.XmlSiteMapProvider" siteMapFile="~/Web.sitemap" securityTrimmingEnabled="true" />
      </providers>
    </siteMap>
    <pages>
      <controls>
        <add tagPrefix="ajaxToolkit" assembly="AjaxControlToolkit" namespace="AjaxControlToolkit" />
      </controls>
    </pages>
  </system.web>
  <entityFramework>
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
      <parameters>
        <parameter value="v11.0" />
      </parameters>
    </defaultConnectionFactory>
  </entityFramework>
</configuration>


and my database tables having 2 tables
1. Roles - RoleID, RoleName
2. Users - [UserId],[Username],[Password],[Email],[CreatedDate],[LastLoginDate],[RoleId],[Status]

Please help me... I am not able to understand exact problem.
Posted
Updated 21-Sep-14 21:53pm
v2
Comments
[no name] 22-Sep-14 23:33pm    
have you tried debugging?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900