I have shopping cart web application. when I am running that in my local machine that works fine. But when i hosted my application online i am facing two issue
- when i login and uses my application after some time user automatically signout and redirected to login page.
- some of the pictures retrieved and shown by the datalist control not shown only the text is show
I am using method FormsAuthentication.RedirectFromLoginPage(username, true) for the login the user
my web.config file is
<?xml version="1.0"?>
<!--
For more information on how to configure your ASP.NET application, please visit
http://go.microsoft.com/fwlink/?LinkId=169433
-->
<configuration>
<connectionStrings>
<add name="shopingConnectionString1" connectionString="workstation id=shoppingpra.mssql.somee.com;packet size=4096;user id=pramuk98;pwd=kumarjha;data source=shoppingpra.mssql.somee.com;persist security info=False;initial catalog=shoppingpra"
providerName="System.Data.SqlClient" />
</connectionStrings>
<system.web>
<compilation debug="true" targetFramework="4.0" />
<authentication mode="Forms">
<forms defaultUrl="default.aspx" loginUrl="login1.aspx" timeout="1000000" cookieless="AutoDetect" ></forms>
</authentication>
<authorization>
<deny users="?"/>
</authorization>
</system.web>
</configuration>
And the login page code i'm using
User Name<br />
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server"
ControlToValidate="TextBox1" ErrorMessage="fill usename "></asp:RequiredFieldValidator>
<br />
Password<br />
<asp:TextBox ID="TextBox2" runat="server" TextMode="Password"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server"
ControlToValidate="TextBox2" ErrorMessage="fill password"></asp:RequiredFieldValidator>
<br />
<asp:ImageButton ID="ImageButton3" runat="server" AlternateText="sign in"
onclick="ImageButton3_Click" ImageUrl="~/img/str/buttons/sign in.bmp" />
protected void ImageButton3_Click(object sender, ImageClickEventArgs e)
{
int flag = 0;
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["shopingConnectionString1"].ConnectionString);
string s = "select * from login";
SqlCommand com = new SqlCommand(s, con);
con.Open();
if (con.State == ConnectionState.Open)
{
SqlDataReader dtr;
dtr = com.ExecuteReader();
while (dtr.Read())
{
if (dtr[0].ToString().Equals(TextBox1.Text) && dtr[1].ToString().Equals(TextBox2.Text))
{
flag = 1;
Response.Cookies["uname"].Value = TextBox1.Text;
Response.Cookies["pwd"].Value = TextBox2.Text;
Response.Cookies["role"].Value = dtr[2].ToString();
FormsAuthentication.RedirectFromLoginPage(TextBox1.Text, false);
}
else
{
Label1.Text = "your credential are incorrect";
}
}
For all that issue i changed timeout lots of time and also added session tag to web.config for not works for me know finally i understand authentication has nothing to do with Session.
All authentcation information is stored in the authentication cookie, When a user needs to loggin again, it means that the authentication ticket is expired.
The solution is very simple, add a machine key to your web.config or use this online tool machine key