Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Basics
|
ASP.NET 2.0 Basics If you are new to ASP or ASP.NET programming with version 2.0, this is the forum to begin asking questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old June 5th, 2008, 02:24 AM
Registered User
 
Join Date: Apr 2008
Posts: 9
Thanks: 0
Thanked 1 Time in 1 Post
Default how to implement logout for web apllication?

Hi all,
i am using form based authen. to secure my web application.But when i am trying to logout with FormsAuthentication.SignOut();and then Response.Redirect("../main/Login.aspx")but it gives "HTTP Error 404 - Not Found". My web.config as....
<authentication mode="Forms">
      <forms loginUrl="Login.aspx"
        name=".LOGINAUTH"
        protection="All" timeout="30" path="/" slidingExpiration="true">
        <credentials passwordFormat="Clear">
          <user name="vishal" password="campus"/>
          <user name="manas" password="manas"/>
        </credentials>
     </forms>
    </authentication>
    <machineKey validationKey="AutoGenerate" decryptionKey="AutoGenerate"/>
    <authorization>
      <allow users="*" />
      <deny users="?"/>
    </authorization>
And Login.aspx.cs as.....
 if (FormsAuthentication.Authenticate(txtUserid.Text, txtPassword.Text))
        {
            FormsAuthentication.RedirectFromLoginPage(txtUseri d.Text, chkRemeberMe.Checked);
            FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(
                1, this.txtUserid.Text, DateTime.Now,
                DateTime.Now.AddMinutes(30), this.chkRemeberMe.Checked, "User");
            string cookistr = FormsAuthentication.Encrypt(ticket);
            HttpCookie hcookie = new HttpCookie(FormsAuthentication.FormsCookieName, cookistr);
            if (this.chkRemeberMe.Checked)
            {
                hcookie.Expires = ticket.Expiration;
            }
            hcookie.Path = FormsAuthentication.FormsCookiePath;
            Response.Cookies.Add(hcookie);

            if (txtUserid.Text == "vishal")
            {
               Response.Redirect("../Adminstration.aspx");
            }
            else
            {
                Response.Redirect("../main/NotAuthorized.aspx");
            }

        }

so plz help me for that,,


Vish
 
Old June 5th, 2008, 09:14 AM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

The 404 error is indicating that the page you are redirecting to doesn't exist. This is a very basic error.

It would appear that wherever you are logging out from that "../main/Login.aspx" is not a valid URL.

I would recommend you change your redirect call to use an application root relative URL:

   Response.Redirect("~/main/Login.aspx")

This will get resolved properly to the the page off the root of the application and will therefore work from any page.

-Peter
compiledthoughts.com
 
Old June 6th, 2008, 01:08 AM
Registered User
 
Join Date: Apr 2008
Posts: 9
Thanks: 0
Thanked 1 Time in 1 Post
Default

Quote:
quote:Originally posted by planoie
 The 404 error is indicating that the page you are redirecting to doesn't exist. This is a very basic error.

It would appear that wherever you are logging out from that "../main/Login.aspx" is not a valid URL.

I would recommend you change your redirect call to use an application root relative URL:

   Response.Redirect("~/main/Login.aspx")

This will get resolved properly to the the page off the root of the application and will therefore work from any page.

-Peter
compiledthoughts.com

Thanks a lot Peter,

It Works...! But when i click "back" button on browser it again go to the Administrator.aspx page that means it not kills session.Plz guide for the same.


Vish
 
Old June 6th, 2008, 08:34 AM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

Quote:
quote:Originally posted by divekar.vishal
 But when i click "back" button on browser it again go to the Administrator.aspx page that means it not kills session.

Are you positive? Try going back and then hit refresh. I think you'll find that it will kick you to the login page. This really has nothing to do with ASP.NET but rather with browser page caching. You may need to set an explicit expiry datetime for the page(s) so the browser doesn't cache them.

-Peter
compiledthoughts.com





Similar Threads
Thread Thread Starter Forum Replies Last Post
Web App Error on Logout janetb ASP.NET 2.0 Basics 4 March 25th, 2008 12:30 PM
How to implement unicode in asp web-pages? Swetz Classic ASP Databases 0 May 23rd, 2006 12:17 AM
How to Implement UDDI Web service using Vb.Net sibajibasak .NET Web Services 0 January 31st, 2005 07:38 AM
logout TIME and logout DATE crmpicco Classic ASP Databases 2 January 20th, 2005 12:01 AM
logout TIME and logout DATE crmpicco Classic ASP Basics 0 January 19th, 2005 07:57 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.