473,385 Members | 1,396 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

FormsAuthentication Problem


I have an index.aspx page containing a button and the code in btn click
is
private void Button1_Click(object sender, System.EventArgs e)
{
if(User.Identity.IsAuthenticated)
{
Session["name"]=User.Identity.Name.ToString();
Server.Transfer("welcome.aspx");
}
else
{
Server.Transfer("login.aspx");
}
}
so when an unauthenticated user logs in it shld direct to login page.
and on my login.aspx page the code in submit btn is

private void Button1_Click(object sender, System.EventArgs e)
{

Session["name"]=TextBox1.Text;
string user = TextBox1.Text;
string pwd = TextBox2.Text;

SqlConnection sql = new SqlConnection("data source=localhost;user
id=sa;pwd=;database=bank");
sql.Open();
SqlCommand cmd = new SqlCommand("select * from customer where
cid='"+user+"' and pwd='"+pwd+"'",sql);
SqlDataReader dr = cmd.ExecuteReader();
while(dr.Read())
{
FormsAuthentication.SetAuthCookie(user,ChkBox1.Che cked);
FormsAuthentication.GetRedirectUrl(user,ChkBox1.Ch ecked);
Server.Transfer("welcome.aspx");
}

lb3.Text="Username and Password typed are incorrect. Please Retry";

}

so whenever a user's authentication is verified he shld be redirected
to thw welcome.aspx page...but the strage thing is that it doesnt. The
page is redirected to my index.aspx page.
Somethin strange is happenin with the ReturnUrl=?.

my questions are:
1) what shld i do so that authenticated users can go to the
welcome.aspx page after authentication instead of the index.aspx page?

2) when i tried changin my web.congig setting's to loginUrl=login.aspx
(currently it is index.aspx coz i want unauthenticated users to go to
the home page) I am unable to put a hyperlink that goes to the
index.aspx page. Even on clicking the hyperlink it remains in the
login.aspx page. Why is this happening ? and how to put a
hyperlink/button so that it goes to the index.aspx page?

Apr 10 '06 #1
1 1370
DWS
Rule one of security.
Don't write your own authentication code.
what about user "or 1=1" that might work
or user * might work too.
"thecoolone" wrote:

I have an index.aspx page containing a button and the code in btn click
is
private void Button1_Click(object sender, System.EventArgs e)
{
if(User.Identity.IsAuthenticated)
{
Session["name"]=User.Identity.Name.ToString();
Server.Transfer("welcome.aspx");
}
else
{
Server.Transfer("login.aspx");
}
}
so when an unauthenticated user logs in it shld direct to login page.
and on my login.aspx page the code in submit btn is

private void Button1_Click(object sender, System.EventArgs e)
{

Session["name"]=TextBox1.Text;
string user = TextBox1.Text;
string pwd = TextBox2.Text;

SqlConnection sql = new SqlConnection("data source=localhost;user
id=sa;pwd=;database=bank");
sql.Open();
SqlCommand cmd = new SqlCommand("select * from customer where
cid='"+user+"' and pwd='"+pwd+"'",sql);
SqlDataReader dr = cmd.ExecuteReader();
while(dr.Read())
{
FormsAuthentication.SetAuthCookie(user,ChkBox1.Che cked);
FormsAuthentication.GetRedirectUrl(user,ChkBox1.Ch ecked);
Server.Transfer("welcome.aspx");
}

lb3.Text="Username and Password typed are incorrect. Please Retry";

}

so whenever a user's authentication is verified he shld be redirected
to thw welcome.aspx page...but the strage thing is that it doesnt. The
page is redirected to my index.aspx page.
Somethin strange is happenin with the ReturnUrl=?.

my questions are:
1) what shld i do so that authenticated users can go to the
welcome.aspx page after authentication instead of the index.aspx page?

2) when i tried changin my web.congig setting's to loginUrl=login.aspx
(currently it is index.aspx coz i want unauthenticated users to go to
the home page) I am unable to put a hyperlink that goes to the
index.aspx page. Even on clicking the hyperlink it remains in the
login.aspx page. Why is this happening ? and how to put a
hyperlink/button so that it goes to the index.aspx page?

Apr 11 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: George Durzi | last post by:
When you call FormsAuthentication.SignOut(), is the FormsAuthentication cookie supposed to be destroyed automatically? I'm creating my FormsAuthentication cookie by doing: HttpCookie oCookie =...
4
by: Jeff B | last post by:
I am having a very perplexing problem with setting the user's roles. I have tried to figure this out for 2 days now. When the user logs in to the site, I retrieve the roles from the database and...
3
by: Phil Certain | last post by:
Hi I'm building a site that has publicly available pages and password protected pages. Publicly available pages reside in: /public and password protected pages reside in: /private
2
by: tshad | last post by:
I have a logon page that is may be called by the Forms Authentication setup. This would put a ReturnURL as part of the URL. I would normally then just issue a: ...
2
by: Grant Merwitz | last post by:
Hi, i am using forms authentication in an ASP.NET project I am setting the Forms authentication cookie by using: FormsAuthentication.RedirectFromLoginPage(UserName.Text, false); Now when i...
4
by: Matthias S. | last post by:
Hi there, I've created an application which is using Forms-based authentification. My Login-Button event handler looks somewhat like this: // validate the input, etc... // sUserName holds now...
5
by: Åženol Akbulak | last post by:
Hello; I use in my web application FormsAuthentication. Also I use Session state (InProc). When a user logged in, I can read Session parameters. (For example Session). Problem is that, when...
2
by: rn5a | last post by:
A web.config file has the following code: <configuration> <system.web> <authentication mode="Forms"> <forms name="NETConnectCookie" loginUrl="Login.aspx"> <credentials passwordFormat="SHA1"/>...
2
by: parez | last post by:
Hi ALl, I had problem with FormsAuthentication.SignOut(). It wasnt working. Looked arround and saw a lot of posts and different solutions to the problem. And some how (i dont nkow what...
0
by: Rodrigo m. Ferreira | last post by:
Can you help me to solve the following problem? on my loggin page I have the code: protected void LoginButton_Click(object sender, EventArgs e) { if(Membership.ValidateUser(TXTUsuario.Text,...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.