Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

FormsAuthentication.Authenticate authenticates but doesn't redirect

Posted on 2011-02-12
2
Medium Priority
?
379 Views
Last Modified: 2013-12-17
Hi,
I have an asp.net application in whose pages are free to view to every one however in it I have added a folder called "Demo" that needs protection and a login page.

In my web.config i have:

    <authentication mode="Forms" >
      <forms loginUrl="Admin.aspx" defaultUrl="DemoFolder/Demo.aspx" name=".ASPNETAUTH" protection="None" path="/" timeout="20" >
        <credentials passwordFormat="Clear">
          <user name="joe" password="test" />
        </credentials>
      </forms>
    </authentication>

In the location section I have:

  <location path="Demo">
    <system.web>
      <authorization>
        <deny users="?"/>
      </authorization>
    </system.web>
  </location>

And in my login_click() event I have:

            if (FormsAuthentication.Authenticate(txtUserName.Text, txtPassword.Text))
            {
                Response.Redirect("~/DemoFolder/Demo.aspx");    
            }
            else
            {
                Msg.Text = "Login failed. Please check your user name and password and try again.";
            }

The Authenticate method definitely works because if I put the wrong passowrkd the Msg.Text will be executed. I have very similar code elsewhere and it works.

Any ideas welcome.
0
Comment
Question by:ilyrian
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 8

Accepted Solution

by:
Yiogi earned 2000 total points
ID: 34880789
Everything looks ok to me, except from the fact that you don't set your authentication cookie anywhere. Since you have a set url to redirect to and you don't want to use RedirectFromLoginPage method you should manually set the cookie. So before Response.Redirect please add this line:

        FormsAuthentication.SetAuthCookie(userName, false);

You can replace false with true to persist the authentication cookie for 50 years. RedirectFromLoginPage sets the cookie for you but you are not using it.
0
 

Author Closing Comment

by:ilyrian
ID: 34882567
Spot on Yiogi, I know it was something to do with the Authentication cookie but it was not doing it for me. You line of code was all that was missing.
Thanks
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…

610 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question