我有购物车网页应用程序。当我在我的本地机器上运行时工作正常。但是,当我在线托管我的申请时,我面临两个问题
我使用方法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";
}
}
答案 0 :(得分:1)
关于注销问题,您是否使用会话来管理登录状态?如果是,请尝试将会话生存期设置为更高的值。
如果未显示图片,则路径可能存在问题(绝对路径)。右键单击图像并检查它尝试从中获取图像的路径。我希望你没有将图片存储在数据库中!您只有图片的链接。正确?
这是您可以在web.config中更改身份验证超时的方法:
<system.web>
<authentication mode="Forms">
<forms timeout="1000000"/>
</authentication>
</system.web>
时间以毫秒为单位。
答案 1 :(得分:0)
对于所有这个问题,我更改了超时的时间,并且还为web.config添加了会话标记,因为我最终知道身份验证与Session没有关系。
所有认证信息都存储在认证cookie中。当用户需要再次登录时,这意味着认证券已过期。
解决方案非常简单,在web.config中添加机器密钥或使用此在线工具 machine key