Unable to get Forms-based Authentication to work

A

Attila

Hello,

I'm new to ASP.NET, and I'm trying to learn how to implement forms
based authentication. However, I don't know what I'm doing wrong.
While the FormsAuthentication.Authenticate method returns true, after
I call FormsAuthentication.RedirectFromLoginPage I am redirected back
to the login page. I would expect that once the Authenticate method is
run, the user should be authenticated, and the user should be able to
view any page on the site.
Any ideas of what I'm doing wrong? Do I need to set a session
variable? Is there something wrong/missing from my web.config file?

Thanks,
Attila

web.config:

<configuration>
<system.web>
<authentication mode="Forms">
<forms name=".helpdesk_admin_dev"
path="/"
loginUrl="LogIn.aspx"
protection="Encryption"
timeout="300">
<credentials passwordFormat="Clear">
<user name="test" password="1234" />
</credentials>
</forms>
</authentication>

<authorization>
<allow users="test" />
<deny users="?" />
</authorization>
</system.web>
</configuration>

LogIn.aspx code:
protected void Login_Click(Object sender, EventArgs E)
{
string strUsername = Username.Value;
string strPassword = Password.Value;

//Validate the username against the web.config file
if(FormsAuthentication.Authenticate(strUsername, strPassword))
{
FormsAuthentication.RedirectFromLoginPage(strUsername, false);
}
else
{
Message.Text = "You did not enter a valid username and password.";
}
}
 
T

Tian Min Huang

Hi Attila,

Please refer to the following MSDN articles for how to implement form based
authentication in asp.net:

HOW TO: Implement Forms-Based Authentication in Your ASP.NET Application by
Using C# .NET
http://support.microsoft.com/?id=301240

HOW TO: Implement Role-Based Security with Forms-Based Authentication in
Your ASP.NET Application by Using Visual C# .NET
http://support.microsoft.com/?id=311495

Hope this helps.

Regards,
HuangTM
This posting is provided "AS IS" with no warranties, and confers no rights.
 
A

Attila

Thank you, but I have already seen those links. From what I can tell
my settings are setup correctly, yet it still doesn't appear to be
working. I had thought that my problem was related to my browser,
although it's currently set to accept all cookies.

Attila
 
J

JD Bee

Hi Buddy!

I had the exact same problem as you did. here is how i solved it:

First, i want you to know i dont fully understand why it works, but it
does. :)

to redirect after login i was using:

Response.Redirect(
FormsAuthentication.GetRedirectUrl(this.Username.Text,false));

i replaced it with:
FormsAuthentication.RedirectFromLoginPage(this.Username.Text,true);

and it now works fine. is it the state cookie param from false to true
or the change of the method, im not sure.
 
J

JD Bee

Hi Buddy!

I had the exact same problem as you did. here is how i solved it:

First, i want you to know i dont fully understand why it works, but it
does. :)

to redirect after login i was using:

Response.Redirect(
FormsAuthentication.GetRedirectUrl(this.Username.Text,false));

i replaced it with:
FormsAuthentication.RedirectFromLoginPage(this.Username.Text,true);

and it now works fine. is it the state cookie param from false to true
or the change of the method, im not sure.
 
T

Tian Min Huang

Hi Attila,

Thanks for your update.

Please check whether your server name contains other characters, say,
underscore character ("_"). Based on my research, Internet Explorer blocks
cookies from a server if the its name contains such characters. Please
refer to the following article for detailed information:

PRB: Session Variables Do Not Persist Between Requests After You Install
Internet Explorer Security Patch MS01-055
http://support.microsoft.com/?id=316112

I look forward to hearing from you.

Have a nice day!

Regards,

HuangTM
Microsoft Online Partner Support
MCSE/MCSD

Get Secure! ¨C www.microsoft.com/security
This posting is provided ¡°as is¡± with no warranties and confers no rights.
 
A

Attila

The problem was that my server name contained uderscores. I removed
the underscores from the server name, and it now works. Thanks.

Attila
 
J

John Kievlan

I will be forever in your debt, friend Tian. I've been
beating my head into the wall over this problem for the
past two weeks... and if I hadn't come across this
thread, I'd *still* be beating my head into the wall. My
server name contained an underscore, and when I started
using ASP.NET, I couldn't store cookies or session
variables... which was EXTREMELY frustrating. Thanks
again.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,535
Members
45,007
Latest member
obedient dusk

Latest Threads

Top