【问题标题】:Deployment issue asp.net web application部署问题 asp.net web 应用程序
【发布时间】:2011-12-13 17:35:41
【问题描述】:

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

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


                }

【问题讨论】:

  • 您可以在web.config中设置表单认证的超时值。
  • 超时值对我不起作用

标签: asp.net asp.net-development-serv


【解决方案1】:

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

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

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

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

时间以毫秒为单位。

【讨论】:

  • 不,我只是使用我编写的FormsAuthentication.RedirectFromLoginPage(username, true)的方法。实际上我不知道如何通过会话管理登录状态。
  • 在这种情况下,设置表单验证超时并检查它是否有效。
  • 我这样做了,但它不起作用
  • 我这样做了,但它不起作用
  • 那么,我猜你在代码中的某个地方覆盖了它。如果您在代码中手动覆盖 web.config 文件中设置的超时,则其优先级较低。
【解决方案2】:

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

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-07-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多