2

我有购物车网络应用程序。当我在本地机器上运行它时,它工作正常。但是当我在线托管我的应用程序时,我面临两个问题

  1. 当我登录并在一段时间后使用我的应用程序时,用户会自动注销并重定向到登录页面。
  2. datalist控件检索并显示的一些图片未显示仅显示文本

我正在使用 FormsAuthentication.RedirectFromLoginPage(username, true) 方法登录用户

我的 web.config 文件是

<?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>

我正在使用的登录页面代码

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";
                    }


                }
4

2 回答 2

1

关于登出问题,您是否使用会话来管理登录状态?如果是,请尝试将会话生命周期设置为更高的值。

如果没有显示图片,则可能是路径(绝对路径)有问题。右键单击图像并检查它试图从中获取图像的路径。我希望你没有将图片存储在数据库中!你只有图片的链接。正确的?

这是您可以在 web.config 中更改身份验证超时的方法:

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

时间以毫秒为单位。

于 2011-10-23T21:39:56.347 回答
0

对于所有这些问题,我更改了 timeout 很多时间,并且还在 web.config 中添加了会话标签,因为我知道最后我知道身份验证与 Session 无关。

所有的认证信息都保存在认证cookie中,当用户需要重新登录时,就意味着认证票据已经过期。

解决方法很简单,在你的web.config中添加一个机器密钥或者使用这个在线工具 机器密钥

于 2011-10-24T22:30:33.780 回答