2

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

  1. when i login and uses my application after some time user automatically signout and redirected to login page.
  2. 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";
                    }


                }
2
  • you can set the timeout value in the web.config for forms authentication. Commented Oct 23, 2011 at 21:35
  • timeout value not works for me Commented Oct 23, 2011 at 21:48

2 Answers 2

1

Regarding the sign-out problem, are you using sessions to manage the logged-in state? If yes, try setting the session lifetime to a higher value.

If pictures are not showing, it might be a problem with the path (absolute path). Right click on the image and check the path it is trying to fetch the image from. I hope you did not store the pictures in the database! You only have the links to the pictures. Right?

This is how you can change the authentication timeout in web.config:

<system.web>
    <authentication mode="Forms">
          <forms timeout="1000000"/>
    </authentication>
</system.web>

The time is in milliseconds.

Sign up to request clarification or add additional context in comments.

5 Comments

No i'm just using the method i write FormsAuthentication.RedirectFromLoginPage(username, true).Actually i don't know how to manage the logged-in state by session.
In that case, set the form authentication timeout and check if it works.
I did this but its not working <authentication mode="Forms" > <forms defaultUrl="default.aspx" loginUrl="login1.aspx" timeout="20000" cookieless="AutoDetect" ></forms> </authentication>
I did this but its not working <authentication mode="Forms" > <forms defaultUrl="default.aspx" loginUrl="login1.aspx" timeout="1000000" cookieless="AutoDetect" ></forms> </authentication>
Then, I guess you are overriding it somewhere in your code. Timeout set in the web.config file will have a lower priority if you are manually overriding it in your code.
0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.