ASP.NET
  Home arrow ASP.NET arrow Page 4 - Database Storage with the ASP.NET Web Matr...
ASP Free Forums 
.NET  
ASP  
ASP Code  
ASP.NET  
ASP.NET Code  
BrainDump  
C#  
Code Examples  
Database  
Database Code  
IIS  
Microsoft Access  
MS SQL Server  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
ASP Web Hosting  
ASP.NET Web Hosting 
Mobile Linux 
App Generation ROI 
Windows Web Hosting
 
IBM® developerWorks 
Sun Developer Network 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
ASP.NET

Database Storage with the ASP.NET Web Matrix: Unsubscribe Page
By: Dan Wellman
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 4
    2005-09-28

    Table of Contents:
  • Database Storage with the ASP.NET Web Matrix: Unsubscribe Page
  • Setting up the Page
  • Calling the Function
  • Setting up a Web Directory Structure

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Database Storage with the ASP.NET Web Matrix: Unsubscribe Page - Setting up a Web Directory Structure


    (Page 4 of 4 )

     

    When the Web Matrix is installed, a folder called Web Matrix Projects is created in the My Documents folder.  This is the folder where the pages you have been making so far will probably be held.  This has been fine up until now, but to test the configuration we have almost completed, a proper web directory structure can be set up that includes a virtual site root.  This will enable us to maintain a folder structure more similar to that of a live web application and will give you better management of document organization.

    Anyway, in Explorer, create a new folder in the Web Matrix Projects folder and call it dataSite.  Drag the login, register and web.config files into this folder and then, also in the folder, create a new folder called private.  Now drag the unsubscribe page into the private folder. 

    Open IIS if you have it installed and navigate to the default web site in the tree-veiw at the far left of the management console.  Right-click on the default web site and select New --> Virtual directory.  This will open the Virtual Directory Creation wizard.  Click Next on the first page to begin and type the alias as dataSite.  Click the Next button again and use the Browse button to navigate to the dataSite folder in the Web Matrix Projects folder that we just created.  Click the Next button, accept the defaults and click the Next button again.  The wizard should notify you that the operation was a success so simply click the Finish button to go back to IIS.  Your folder will now be set up as a virtual directory:

     

    If you don’t have IIS installed, when playing pages in the Web Matrix, you can choose to use either the built in server, or the option to Use or create an IIS Virtual Root.  Selecting this option will do automatically what we have just done in IIS.  If you have IIS installed, I would recommend using it simply to give yourself a better overview and understanding of the management console.

    So that is the directory structure taken care of, to complete the task, you just need to create a second web.config file and make a small change to the login page.  Make sure the first config file is closed and open a new one.  Remove all of the existing text, except for the XML declaration at the top, and add the following code:

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

    Save the file.  The <deny users="?" /> line tells the server to deny any unknown (people that are not logged in) users access to any file in the folder it sits in (the private folder in this case).

    There is just one thing left to do. As IIS will redirect unauthenticated users to the login page, we will need a way to redirect them back to the page they requested once they have logged in.  To this, open up the login page and change the successful login action from displaying a success message to redirecting a visitor:

    If userDetailsName.Tables(0).Rows.Count <> 1 Then
      lblUsernameError.Text = "* Username not known, please <a
    href='register.aspx'>Register</a> with us"
    Else If userDetailsPass.Tables(0).Rows.Count <> 1 Then
      lblPasswordError.Text = "* Password incorrect"
    Else
      FormsAuthentication.RedirectFromLoginPage
    (txtUsername.Text,false)
    End If

    The FormsAuthentication method is what controls the redirect, the txtUsername.Text parameter can be used to specify a default page for the particular user and the Boolean value indicates whether the cookie that is created is a permanent cookie that hangs around on the user's computer after the browser is closed, or a session cookie that is destroyed once the session is over.

    You can test this page by using the play button to open the Unsubscribe page.  If everything goes according to plan, however, the Unsubscribe page should not load.  Instead, the Login page should open, with the referring page appended to the URL as a query string.  Upon a successful login, the web server will redirect back to the page in the query string.  If you get errors when testing this page, you may need to shut down the Web Matrix application, then re-open it and open the login page.  View the login page but don’t actually log in.  Then open the Unsubscribe page and play it.  It would seem that the built-in web server of the Web Matrix still needs a little tweaking, as occasionally it may need to be coerced into doing what you want it to!  After you have successfully tested it, check the database table to check that the user has been removed. 

    So now we have covered inserting, reading and deleting from a data source using the preconfigured wizards. The next article will discuss updating data, such as when a user wants to change their password or account information.


    DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.

       · Welcome to the third article in the built-in code wizard series. I hope you find it...
     

    ASP.NET ARTICLES

    - Developing a Mini ASP.NET AJAX Server Centri...
    - Disadvantages of the ASP.NET MVC Framework
    - Advantages of the ASP.NET MVC Approach
    - ASP.NET Web Forms Weaknesses
    - ASP.NET Web Forms Meets ASP.NET MVC
    - Source Code for Saving and Retrieving Data w...
    - Using GridView to Save and Retrieve Data wit...
    - Handling Dynamic Images in ASP.NET 3.5 AJAX ...
    - Retrieving Data with AJAX and the GridView C...
    - Playing with Images in ASP.NET 3.5 AJAX Appl...
    - Saving and Retrieving Data with AJAX
    - Enhancing PHP Via the ASP.NET AJAX Framework...
    - Enhancing PHP Programming with the ASP.NET A...
    - Classes and ASP.NET AJAX
    - Using ASP.NET AJAX

     
    Best Practices for Windows Vista Migration Presentation
    Dell and Microsoft recently held a series of face-to-face seminars entitled, &qu....

     
    Creating a Culture for Code Reuse
    If you oversee development teams you know that like it or not proprietary and ex....

     
    Keys to Web Application Acceleration: Advances in Delivery Systems
    Accelerate Web apps by up to 5x. Ensure significantly faster access to the Web a....

     
    Optimizing Application Monitoring
    Tired of finding out from your customers that you're offline? This white paper e....

     
    Solaris to Solaris Migration -- Migrating applications from Sun SPARC to Dell PowerEdge R900
    This comprehensive Migration Guide reviews the approach that Principled Technolo....

     




    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway
    Stay green...Green IT