TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Kavita B
NA
123
183.2k
Problem with login status control
Jun 13 2011 12:29 AM
Hi,
I am using the login status control in my master page.. My login control is a web custom control which i have created. When a user logs in i have redirected user to home.aspx. But it is not navigating/redirecting user to home.aspx... i have attached the code. plzz go throu and let me know where i have made a mistake..
MASTER PAGE :
<%@ Master Language="C#" AutoEventWireup="true" CodeFile="MasterPage.master.cs" Inherits="MasterPage" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
<asp:ContentPlaceHolder id="head" runat="server">
</asp:ContentPlaceHolder>
</head>
<body>
<form id="form1" runat="server">
<div>
<table width="700" border="0" align="center" cellpadding="1" cellspacing="1">
<tr>
<td colspan="2"> [Project title/image can be placed here]</td>
</tr>
<tr>
<td colspan="2">
<table width="100%" border="0" cellspacing="1" cellpadding="1">
<tr>
<td style="width: 54px"><a href="home.aspx">Home</a></td>
<td style="width: 54px"><asp:LoginStatus ID="LoginStatus1" runat="server" LoginText="LogIn" LogoutText="Logout" LogoutPageUrl="~/home.aspx" OnLoggedOut="LoginStatus1_LoggedOut" />
</td>
<td>
</td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td><a href="register.aspx">New User? Register</a></td>
</tr>
</table>
</td>
</tr>
<tr>
<td colspan="2">
</td>
</tr>
<tr>
<td colspan="2"> <asp:contentplaceholder id="ContentPlaceHolder1" runat="server">
</asp:contentplaceholder></td>
</tr>
<tr>
<td>
</td>
<td>
</td>
</tr>
</table>
</div>
</form>
</body>
</html>
=================================================================================
WEB USER CONTROL:
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="login.ascx.cs" Inherits="login" %>
<asp:PlaceHolder ID="pl1" runat="server">
<fieldset style="width:400; background-color:White">
<legend>Existing users login</legend>
<table border="0" align="left" cellpadding="1" cellspacing="3" style="width: 324px; font-family: 'Times New Roman';">
<tr>
<td align="right">UserName:</td>
<td style="width: 168px" align="left"> <asp:TextBox ID="txtuser" runat="server"></asp:TextBox></td>
<td align="left"> <asp:RequiredFieldValidator ID="requsername" runat="server" Display="Dynamic"
ErrorMessage="*" ControlToValidate="txtuser"></asp:RequiredFieldValidator></td>
</tr>
<tr>
<td align="right">Password:</td>
<td style="width: 168px" align="left"> <asp:TextBox ID="txtpassword" runat="server" TextMode="Password"></asp:TextBox></td>
<td align="left"> <asp:RequiredFieldValidator ID="reqpassword" runat="server" Display="Dynamic"
ErrorMessage="*" ControlToValidate="txtpassword"></asp:RequiredFieldValidator></td>
</tr>
<tr>
<td> </td>
<td style="width: 168px"> <asp:ImageButton ID="imglogin" runat="server" ImageUrl="~/images/Login_button.gif" Width="55px" /></td>
<td> </td>
</tr>
<tr>
<td>
</td>
<td style="width: 168px">
<asp:Label ID="lblmsg" runat="server" ForeColor="Red" Visible="False"></asp:Label></td>
<td>
</td>
</tr>
</table>
</fieldset>
</asp:PlaceHolder>
=========================================================================================
CODE BEHIND FOR WEB USER CONTROL:
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
public partial class login : System.Web.UI.UserControl
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void imglogin_Click(object sender, ImageClickEventArgs e)
{
//try
//{
SqlConnection CON = new SqlConnection(ConfigurationManager.ConnectionStrings["ProjectTrackingConnectionString"].ConnectionString);
CON.Open();
SqlCommand cmd = new SqlCommand("select UserName,Password from login_master", CON);
SqlDataReader dtr;
dtr = cmd.ExecuteReader();
while (dtr.Read())
{
if ((dtr["UserName"].ToString() == txtuser.Text) && (dtr["Password"].ToString() == base64Decode(txtpassword.Text)))
{
Session["user"] = txtuser.Text;
Response.Redirect("home.aspx");
}
else
{
lblmsg.Text = "Invalid UserName/Password!";
}
}
dtr.Close();
CON.Close();
//}
//catch ()
//{
//}
}
public string base64Decode(string sData)
{
System.Text.UTF8Encoding encoder = new System.Text.UTF8Encoding();
System.Text.Decoder utf8Decode = encoder.GetDecoder();
byte[] todecode_byte = Convert.FromBase64String(sData);
int charCount = utf8Decode.GetCharCount(todecode_byte, 0, todecode_byte.Length);
char[] decoded_char = new char[charCount];
utf8Decode.GetChars(todecode_byte, 0, todecode_byte.Length, decoded_char, 0);
string result = new String(decoded_char);
return result;
}
}
Reply
Answers (
2
)
Difference between skin file and Css file
calender events