Forms Auth keeps going to logon page

Ask a Question related to ASP.NET Security, Design and Development.

  1. #1

    Default Forms Auth keeps going to logon page

    Hi,

    I am using forms authentication for a web application I am writing. I query
    a SQL server database to find a matching username and password then create
    an encrypted cookie. I then redirect to my main menu page. However, when I
    select a menu and try to jump to another page, it keeps taking me back to my
    logon page ! Can anybody suggest what I am doing wrong, I enclose a sample
    of my web.config file and a sample of the code that creates the
    authentication cookie.
    Thanks in advance.

    Andy

    Web.Config

    <authentication mode="None">
    <forms name=".RNWEBAUTH" loginUrl="RNLogon.aspx" protection="All"
    timeout="60"></forms>
    </authentication>
    <authorization>
    <deny users="?" />
    <allow users="*" />
    </authorization>

    Logon.aspx

    FormsAuthenticationTicket tkt = new FormsAuthenticationTicket( 1,

    Username.Text,

    DateTime.Now,

    DateTime.Now.AddMinutes( 30 ),

    false,

    strAccess,

    FormsAuthentication.FormsCookiePath );
    //
    // Hash the cookie for security
    //
    string hash = FormsAuthentication.Encrypt( tkt );
    HttpCookie ck = new HttpCookie( FormsAuthentication.FormsCookieName,hash );

    //
    // Add cookie to the response
    //
    Response.Cookies.Add( ck );
    Response.Cookies[ "UserID" ].Value = nUserID.ToString();
    Response.Cookies[ "UserID" ].Expires = DateTime.MaxValue;
    Response.Cookies[ "Access" ].Value = strAccess;
    Response.Cookies[ "Access" ].Expires = DateTime.MaxValue;

    //
    // Jump to main menu page
    //
    Response.Redirect( strRedirect,true );


    Andy Fraser Guest

  2. Similar Questions and Discussions

    1. Forms Auth Info passed to Windows Auth?
      The requirement is to build an ASP.Net intranet application, so external users can log in to the main web portal via forms authentication, using...
    2. Help with forms auth
      Hi, I am using forms Auth on my WEB APP. I am checking the credentials in sql server. When a user request any page other than login.aspx they get...
    3. Configuring Windows Auth & Forms Auth in Asp.Net
      Configuring Windows Auth & Forms Auth in Asp.Ne Hi, I've configured a web app to use windows authentication and also set up two separate...
    4. Error page that is not in "Forms Auth"
      Hi! My web application directory is under Forms Authentication. So if you go to page1.aspx you will be redirected to login.aspx. login.aspx...
    5. 9iLite - CONS-10004: USER_INVALID in Consolidator auth; Logon denied
      Hey all, We get the above error when trying to sync my hand held to oracle. I have webtogo running as a standalone server. I am just trying to...
  3. #2

    Default Re: Forms Auth keeps going to logon page

    Try using something like:

    string name = NameText.Text;
    string password = PasswordText.Text;

    if(FormsAuthentication.Authenticate(name,password) )
    {
    FormsAuthentication.RedirectFromLogonPage(name, false);
    }

    NOTE: You do not set the cookie for authentication using Response.Cookies.
    This is why your app is blowing up. You can do the following, if you want to
    use Response.Redirect:

    FormsAuthentication.GetAuthCookie(name, false);
    Response.Redirect("myFavoritePage.aspx");

    --
    Gregory A. Beamer
    MVP; MCP: +I, SE, SD, DBA

    ************************************************** ********************
    Think Outside the Box!
    ************************************************** ********************
    "Andy Fraser" <news@andyfraser.co.uk> wrote in message
    news:1067895940.781891@ananke.eclipse.net.uk...
    > Hi,
    >
    > I am using forms authentication for a web application I am writing. I
    query
    > a SQL server database to find a matching username and password then create
    > an encrypted cookie. I then redirect to my main menu page. However, when I
    > select a menu and try to jump to another page, it keeps taking me back to
    my
    > logon page ! Can anybody suggest what I am doing wrong, I enclose a sample
    > of my web.config file and a sample of the code that creates the
    > authentication cookie.
    > Thanks in advance.
    >
    > Andy
    >
    > Web.Config
    >
    > <authentication mode="None">
    > <forms name=".RNWEBAUTH" loginUrl="RNLogon.aspx" protection="All"
    > timeout="60"></forms>
    > </authentication>
    > <authorization>
    > <deny users="?" />
    > <allow users="*" />
    > </authorization>
    >
    > Logon.aspx
    >
    > FormsAuthenticationTicket tkt = new FormsAuthenticationTicket( 1,
    >
    > Username.Text,
    >
    > DateTime.Now,
    >
    > DateTime.Now.AddMinutes( 30 ),
    >
    > false,
    >
    > strAccess,
    >
    > FormsAuthentication.FormsCookiePath );
    > //
    > // Hash the cookie for security
    > //
    > string hash = FormsAuthentication.Encrypt( tkt );
    > HttpCookie ck = new HttpCookie(
    FormsAuthentication.FormsCookieName,hash );
    >
    > //
    > // Add cookie to the response
    > //
    > Response.Cookies.Add( ck );
    > Response.Cookies[ "UserID" ].Value = nUserID.ToString();
    > Response.Cookies[ "UserID" ].Expires = DateTime.MaxValue;
    > Response.Cookies[ "Access" ].Value = strAccess;
    > Response.Cookies[ "Access" ].Expires = DateTime.MaxValue;
    >
    > //
    > // Jump to main menu page
    > //
    > Response.Redirect( strRedirect,true );
    >
    >

    Cowboy \(Gregory A. Beamer\) Guest

  4. #3

    Default Re: Forms Auth keeps going to logon page

    I was experiencing a problem with a project that worked fine on my dev
    box, but when I deployed to a standalone windows 2000 server, the forms
    authentication stopped working...kept on being redirected to the login
    page.

    In my situation, it turned out that the cause was due to the server not
    being located on the same domain that the users were on, e.g. setting up
    the server host name as [url]www.fred.com[/url], while the network was
    [url]www.notfred.com[/url].

    Moving the server, so that it became a subdomain of [url]www.notfred.com[/url]
    solved our problem...

    e.g. zeus.notfred.com

    I think what was happening, was internally, when we connected to the
    windows 2000 server, and IE saw the server a strange domain, not
    matching the network domain that the IE user was on, and IE default
    setting is not to accept cookies from strange domains on the LAN.

    On the internet, IE happily accepts the cookies.

    Changing the domain of the server, to be part of ( a subdomain) of
    notfred.com solved our problem, and suddenly IE accepted cookies (
    without any pop up message ), from the subdomain'ed server, and thus the
    server was able to create a session for the user after logging in.

    Without accepting cookies, IIS is unable to establish a session for the
    user.

    Hope this helps...

    regards

    Alan Hemmings
    [email]alan@net-catalogue.co.uk[/email]
    -powerful yet affordable web hosting, run by a small personal family
    business-

    “..the dreamers of the day are dangerous men, for they may act out their
    dreams with open eyes to make them reality.” T.E. Lawrence (Lawrence of
    Arabia)



    *** Sent via Developersdex [url]http://www.developersdex.com[/url] ***
    Don't just participate in USENET...get rewarded for it!
    alan Hemmings Guest

  5. #4

    Default Re: Forms Auth keeps going to logon page

    Gregory,

    It is my understanding that FormsAuthentication.Authenticate authenticates
    the username and password against a list held in the web.config file. I need
    to authenticate from usernames and passwords held on a database so I thought
    that I could not use FormsAuthentication.Authenticate. So I basically do a
    SQL query and if I get a valid match, call the code given in my initial
    post. Do I need to do something different to get the forms authentication to
    work when authenticating from a database rather than web.config ?

    Andy

    "Cowboy (Gregory A. Beamer)" <NoSpamMgbworld@comcast.netNoSpamM> wrote in
    message news:ufk01%236oDHA.688@TK2MSFTNGP10.phx.gbl...
    > Try using something like:
    >
    > string name = NameText.Text;
    > string password = PasswordText.Text;
    >
    > if(FormsAuthentication.Authenticate(name,password) )
    > {
    > FormsAuthentication.RedirectFromLogonPage(name, false);
    > }
    >
    > NOTE: You do not set the cookie for authentication using Response.Cookies.
    > This is why your app is blowing up. You can do the following, if you want
    to
    > use Response.Redirect:
    >
    > FormsAuthentication.GetAuthCookie(name, false);
    > Response.Redirect("myFavoritePage.aspx");
    >
    > --
    > Gregory A. Beamer
    > MVP; MCP: +I, SE, SD, DBA
    >
    > ************************************************** ********************
    > Think Outside the Box!
    > ************************************************** ********************
    > "Andy Fraser" <news@andyfraser.co.uk> wrote in message
    > news:1067895940.781891@ananke.eclipse.net.uk...
    > > Hi,
    > >
    > > I am using forms authentication for a web application I am writing. I
    > query
    > > a SQL server database to find a matching username and password then
    create
    > > an encrypted cookie. I then redirect to my main menu page. However, when
    I
    > > select a menu and try to jump to another page, it keeps taking me back
    to
    > my
    > > logon page ! Can anybody suggest what I am doing wrong, I enclose a
    sample
    > > of my web.config file and a sample of the code that creates the
    > > authentication cookie.
    > > Thanks in advance.
    > >
    > > Andy
    > >
    > > Web.Config
    > >
    > > <authentication mode="None">
    > > <forms name=".RNWEBAUTH" loginUrl="RNLogon.aspx" protection="All"
    > > timeout="60"></forms>
    > > </authentication>
    > > <authorization>
    > > <deny users="?" />
    > > <allow users="*" />
    > > </authorization>
    > >
    > > Logon.aspx
    > >
    > > FormsAuthenticationTicket tkt = new FormsAuthenticationTicket( 1,
    > >
    > > Username.Text,
    > >
    > > DateTime.Now,
    > >
    > > DateTime.Now.AddMinutes( 30 ),
    > >
    > > false,
    > >
    > > strAccess,
    > >
    > > FormsAuthentication.FormsCookiePath );
    > > //
    > > // Hash the cookie for security
    > > //
    > > string hash = FormsAuthentication.Encrypt( tkt );
    > > HttpCookie ck = new HttpCookie(
    > FormsAuthentication.FormsCookieName,hash );
    > >
    > > //
    > > // Add cookie to the response
    > > //
    > > Response.Cookies.Add( ck );
    > > Response.Cookies[ "UserID" ].Value = nUserID.ToString();
    > > Response.Cookies[ "UserID" ].Expires = DateTime.MaxValue;
    > > Response.Cookies[ "Access" ].Value = strAccess;
    > > Response.Cookies[ "Access" ].Expires = DateTime.MaxValue;
    > >
    > > //
    > > // Jump to main menu page
    > > //
    > > Response.Redirect( strRedirect,true );
    > >
    > >
    >
    >

    Andy Fraser Guest

  6. #5

    Default Re: Forms Auth keeps going to logon page

    Andy,
    The sample IBuySpy portal is an excellent example of
    custom forms authentication.
    You can use your own code to authenticate the user (check
    user credentials) and if the user is valid, just call
    FormsAuthentication.RedirectFromLogonPage(name, false);
    >-----Original Message-----
    >Gregory,
    >
    >It is my understanding that
    FormsAuthentication.Authenticate authenticates
    >the username and password against a list held in the
    web.config file. I need
    >to authenticate from usernames and passwords held on a
    database so I thought
    >that I could not use FormsAuthentication.Authenticate. So
    I basically do a
    >SQL query and if I get a valid match, call the code given
    in my initial
    >post. Do I need to do something different to get the
    forms authentication to
    >work when authenticating from a database rather than
    web.config ?
    >
    >Andy
    >
    >"Cowboy (Gregory A. Beamer)"
    <NoSpamMgbworld@comcast.netNoSpamM> wrote in
    >message news:ufk01%236oDHA.688@TK2MSFTNGP10.phx.gbl...
    >> Try using something like:
    >>
    >> string name = NameText.Text;
    >> string password = PasswordText.Text;
    >>
    >> if(FormsAuthentication.Authenticate(name,password) )
    >> {
    >> FormsAuthentication.RedirectFromLogonPage(name,
    false);
    >> }
    >>
    >> NOTE: You do not set the cookie for authentication
    using Response.Cookies.
    >> This is why your app is blowing up. You can do the
    following, if you want
    >to
    >> use Response.Redirect:
    >>
    >> FormsAuthentication.GetAuthCookie(name, false);
    >> Response.Redirect("myFavoritePage.aspx");
    >>
    >> --
    >> Gregory A. Beamer
    >> MVP; MCP: +I, SE, SD, DBA
    >>
    >>
    ************************************************** *********
    ***********
    >> Think Outside the Box!
    >>
    ************************************************** *********
    ***********
    >> "Andy Fraser" <news@andyfraser.co.uk> wrote in message
    >> news:1067895940.781891@ananke.eclipse.net.uk...
    >> > Hi,
    >> >
    >> > I am using forms authentication for a web application
    I am writing. I
    >> query
    >> > a SQL server database to find a matching username and
    password then
    >create
    >> > an encrypted cookie. I then redirect to my main menu
    page. However, when
    >I
    >> > select a menu and try to jump to another page, it
    keeps taking me back
    >to
    >> my
    >> > logon page ! Can anybody suggest what I am doing
    wrong, I enclose a
    >sample
    >> > of my web.config file and a sample of the code that
    creates the
    >> > authentication cookie.
    >> > Thanks in advance.
    >> >
    >> > Andy
    >> >
    >> > Web.Config
    >> >
    >> > <authentication mode="None">
    >> > <forms name=".RNWEBAUTH" loginUrl="RNLogon.aspx"
    protection="All"
    >> > timeout="60"></forms>
    >> > </authentication>
    >> > <authorization>
    >> > <deny users="?" />
    >> > <allow users="*" />
    >> > </authorization>
    >> >
    >> > Logon.aspx
    >> >
    >> > FormsAuthenticationTicket tkt = new
    FormsAuthenticationTicket( 1,
    >> >
    >> > Username.Text,
    >> >
    >> > DateTime.Now,
    >> >
    >> > DateTime.Now.AddMinutes( 30 ),
    >> >
    >> > false,
    >> >
    >> > strAccess,
    >> >
    >> > FormsAuthentication.FormsCookiePath );
    >> > //
    >> > // Hash the cookie for security
    >> > //
    >> > string hash = FormsAuthentication.Encrypt( tkt );
    >> > HttpCookie ck = new HttpCookie(
    >> FormsAuthentication.FormsCookieName,hash );
    >> >
    >> > //
    >> > // Add cookie to the response
    >> > //
    >> > Response.Cookies.Add( ck );
    >> > Response.Cookies[ "UserID" ].Value = nUserID.ToString
    ();
    >> > Response.Cookies[ "UserID" ].Expires =
    DateTime.MaxValue;
    >> > Response.Cookies[ "Access" ].Value = strAccess;
    >> > Response.Cookies[ "Access" ].Expires =
    DateTime.MaxValue;
    >> >
    >> > //
    >> > // Jump to main menu page
    >> > //
    >> > Response.Redirect( strRedirect,true );
    >> >
    >> >
    >>
    >>
    >
    >
    >.
    >
    Guest

  7. #6

    Default Re: Forms Auth keeps going to logon page

    sorry for separate postings . here is another link that i
    thot u might find useful :
    [url]http://www.codeproject.com/aspnet/AspNetCustomAuth.asp[/url]
    >-----Original Message-----
    >Gregory,
    >
    >It is my understanding that
    FormsAuthentication.Authenticate authenticates
    >the username and password against a list held in the
    web.config file. I need
    >to authenticate from usernames and passwords held on a
    database so I thought
    >that I could not use FormsAuthentication.Authenticate. So
    I basically do a
    >SQL query and if I get a valid match, call the code given
    in my initial
    >post. Do I need to do something different to get the
    forms authentication to
    >work when authenticating from a database rather than
    web.config ?
    >
    >Andy
    >
    >"Cowboy (Gregory A. Beamer)"
    <NoSpamMgbworld@comcast.netNoSpamM> wrote in
    >message news:ufk01%236oDHA.688@TK2MSFTNGP10.phx.gbl...
    >> Try using something like:
    >>
    >> string name = NameText.Text;
    >> string password = PasswordText.Text;
    >>
    >> if(FormsAuthentication.Authenticate(name,password) )
    >> {
    >> FormsAuthentication.RedirectFromLogonPage(name,
    false);
    >> }
    >>
    >> NOTE: You do not set the cookie for authentication
    using Response.Cookies.
    >> This is why your app is blowing up. You can do the
    following, if you want
    >to
    >> use Response.Redirect:
    >>
    >> FormsAuthentication.GetAuthCookie(name, false);
    >> Response.Redirect("myFavoritePage.aspx");
    >>
    >> --
    >> Gregory A. Beamer
    >> MVP; MCP: +I, SE, SD, DBA
    >>
    >>
    ************************************************** *********
    ***********
    >> Think Outside the Box!
    >>
    ************************************************** *********
    ***********
    >> "Andy Fraser" <news@andyfraser.co.uk> wrote in message
    >> news:1067895940.781891@ananke.eclipse.net.uk...
    >> > Hi,
    >> >
    >> > I am using forms authentication for a web application
    I am writing. I
    >> query
    >> > a SQL server database to find a matching username and
    password then
    >create
    >> > an encrypted cookie. I then redirect to my main menu
    page. However, when
    >I
    >> > select a menu and try to jump to another page, it
    keeps taking me back
    >to
    >> my
    >> > logon page ! Can anybody suggest what I am doing
    wrong, I enclose a
    >sample
    >> > of my web.config file and a sample of the code that
    creates the
    >> > authentication cookie.
    >> > Thanks in advance.
    >> >
    >> > Andy
    >> >
    >> > Web.Config
    >> >
    >> > <authentication mode="None">
    >> > <forms name=".RNWEBAUTH" loginUrl="RNLogon.aspx"
    protection="All"
    >> > timeout="60"></forms>
    >> > </authentication>
    >> > <authorization>
    >> > <deny users="?" />
    >> > <allow users="*" />
    >> > </authorization>
    >> >
    >> > Logon.aspx
    >> >
    >> > FormsAuthenticationTicket tkt = new
    FormsAuthenticationTicket( 1,
    >> >
    >> > Username.Text,
    >> >
    >> > DateTime.Now,
    >> >
    >> > DateTime.Now.AddMinutes( 30 ),
    >> >
    >> > false,
    >> >
    >> > strAccess,
    >> >
    >> > FormsAuthentication.FormsCookiePath );
    >> > //
    >> > // Hash the cookie for security
    >> > //
    >> > string hash = FormsAuthentication.Encrypt( tkt );
    >> > HttpCookie ck = new HttpCookie(
    >> FormsAuthentication.FormsCookieName,hash );
    >> >
    >> > //
    >> > // Add cookie to the response
    >> > //
    >> > Response.Cookies.Add( ck );
    >> > Response.Cookies[ "UserID" ].Value = nUserID.ToString
    ();
    >> > Response.Cookies[ "UserID" ].Expires =
    DateTime.MaxValue;
    >> > Response.Cookies[ "Access" ].Value = strAccess;
    >> > Response.Cookies[ "Access" ].Expires =
    DateTime.MaxValue;
    >> >
    >> > //
    >> > // Jump to main menu page
    >> > //
    >> > Response.Redirect( strRedirect,true );
    >> >
    >> >
    >>
    >>
    >
    >
    >.
    >
    Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139