Hello to all.I have this project and I must say I am quite stumped with this ASP.Net ( I just can't feel the freedom when I was using JSP:-| ) Anyways the problem is this:
After connecting to the database and verifying that the given password and username was correct I want my program to go to another page called "admin.aspx" and I want no one else but the user to be able to reach that page.Now please keep in mind that I can't use any .Net tools such as login toolbox or verify toolbox. I have to write it myself.Don't worry I finished the verifying part however questions:
How do you forward a page once it is checked?
How do you limit the people that enters your site so they won't enter your admin page?
( Please keep in mind that I am writing in C# not VB )

The codes that I am using :

the default.aspx page which where the user will log in from:

<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en-AU">

<head>


  <title>lazy days ( intro )</title>



  <link rel="stylesheet" type="text/css" href="css/html.css" media="screen, projection, tv " />
  <link rel="stylesheet" type="text/css" href="css/layout.css" media="screen, projection, tv" />
  <link rel="stylesheet" type="text/css" href="css/print.css" media="print" />

</head>


<body>

<!-- CONTENT: Holds all site content except for the footer.  This is what causes the footer to stick to the bottom -->
<div id="content">



  <!-- HEADER: Holds title, subtitle and header images -->
  <div id="header">

    <div id="title">
      <h1>John Roach</h1>
      <h2 style="right: 85px; top: 7px">a home page</h2>
    </div>

    <img src="images/bg/balloons.gif" alt="balloons" class="balloons" />
    <img src="images/bg/header_left.jpg" alt="left slice" class="left" />
    <img src="images/bg/header_right.jpg" alt="right slice" class="right" />

  </div>



  <!-- MAIN MENU: Top horizontal menu of the site.  Use class="here" to turn the current page tab on -->
  <div id="mainMenu">
    <ul class="floatRight">
      <li><a href="Default.aspx" title="Home Page" class="here">Home </a></li>
      <li><a href="projects.aspx" title="Projects by John Roach">Projects</a></li>
      <li><a href="cv.aspx" title="CV/Resume">CV/Resume</a></li>
      <li><a href="downloads.aspx" title="Downloads">Downloads</a></li>
      <li><a href="contact.aspx" title="Get in touch" class="last">Contact</a></li>
    </ul>
  </div>




  <!-- PAGE CONTENT BEGINS: This is where you would define the columns (number, width and alignment) -->
  <div id="page">


    <!-- 25 percent width column, aligned to the left -->
    <div class="width25 floatLeft leftColumn">

      <h1>
          Home</h1>

      <ul class="sideMenu">
        <li class="here">Welcome to my page&nbsp;<ul>
            <li><a href="#fluidity" title="Jump to section">Book of Fluidity</a></li>
            <li><a href="#coding" title="Jump to section">Coding</a></li>
          </ul>
        </li>
      </ul>
        <ul>
        </ul>
        <ul>
        </ul>
        <ul>
        </ul>
        <ul>
        </ul>
    </div>




    <!-- 75 percent width column, aligned to the right -->
    <div class="width75 floatRight">


      <!-- Gives the gradient block -->
      <div class="gradient">

        

        <h1>
            Welcome to my home page</h1>
        

        <p>
          This template quickly and easily allows for one, two, three or even four column layouts.  This is done with simple <acronym title="Cascading Style Sheet">CSS</acronym> classes that can be used over and over again.  To learn more about it, follow <a href="help.html" title="View help">this link</a>.  The template itself is valid <acronym title="eXtensible Hypertext Markup Language">XTHML</acronym> 1.0 strict and <i>almost</i> valid CSS.  The almost is added in there because CSS expressions were used.  You can read more about that <a href="#expressions" title="Read about CSS expressions">here</a>.
        </p>

        <blockquote class="go">
          <p>
            This template doesn't use fixed columns.  With a few simple CSS classes you can quickly change the appearance.  <a href="help.html" title="View help">Click here</a> to learn how.
          </p>
        </blockquote>

        <p>
          Since this template is fluid width and the font sizes are defined relatively, you can <b>change font size without breaking the layout</b>.  The fluid width also means that people with higher resolutions aren't constrained.
        </p>

        <p>
          Total size of the images used is just under 25 <acronym title="kilobytes">kb</acronym>, so that's good news to all the dial-up users.  The code behind the template is semantically written which means that it is widely supported.  As for the browsers, it displays consistently in the usual suspects:
        </p>


        <ul>
          <li><b>Firefox</b> of course</li>
          <li><b>Opera</b> sure, why not</li>
          <li><b>Netscape</b> like firefox's less attractive cousin at the dance</li>
          <li><b>Internet Explorer</b> ...</li>
          <li><b>Safari</b> cause macs are computers too</li>
        </ul>

      </div>





      <div class="gradient">

        <a name="coding"></a>

        <h1>Coding</h1>
        <h2>Image Alignment and The Header</h2>

        <p>
          <a href="http://www.mozilla.com/firefox/" title="Get Firefox"><img src="images/firefox.jpg" alt="pic" class="floatLeft"/></a>
          Images are fully supported using the <i>floatLeft</i> and <i>floatRight</i> classes.  Just apply one of them to the image you want to position.  Images that have link tags around them will also have a nifty rollover effect, as long as you're using a standards complients browser.  If you're not, well then no rollover effect for you.
        </p>

        <p>
          The site header images are <a href="images/bg/header_left.jpg" title="View slice one">two</a> <a href="images/bg/header_right.jpg" title="View slice two">slices</a> and a repeated background.  Using the same approach, and a little bit of photoshop, you should be able to easily replace them.  However, since they were created by me, you're welcome to use them in any projects you might like.
        </p>

        <h2>The Footer</h2>
        <p>
          A variation on the <a href="http://www.themaninblue.com/experiment/footerStickAlt/" title="View footerStickAlt code">footerStickAlt</a> technique is used to force the site footer to the bottom of the page if there isn't enough content to push it down.  This means your template will always look tidy and you won't have to worry about a lonely footer, hanging out halfway up your page.
        </p>

        <a name="expressions"></a>

        <h2>Readability using Maximum Width</h2>
        <p>
          To improve readability of this template (since it is fluid), the width is capped at 1000 pixels.  This seems like a pretty reasonable thing to do and that's why CSS has thoughtfully included the max-width property.  Unfortunately, IE decided it didn't need no stinkin' max-width, so a CSS expression was needed.
        </p>

        <blockquote class="exclamation">
          <p>
            A CSS expression is like a snippet of javascript code that runs in your style sheet.  It's invalid CSS, but only IE pays any attention to it.
          </p>
        </blockquote>

        <p>
          If you're concerned about having valid CSS, take out the expression.  It won't ruin the template in IE, it just means that the content will expand to 100% of the screen width.  All other browsers will behave.
        </p>
         
          <form id="frmlogin" runat="server" action="admin.aspx">
<table>
<tr><td>Login</td></tr>
<tr>
<td>UserName:</td>
<td style="width: 22px">
    <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox></td>
</tr>
<tr>
<td>Password:</td>
<td style="width: 22px">
    <asp:TextBox ID="TextBox2"  runat="server" TextMode="Password"></asp:TextBox></td>
</tr>
<tr>
<td></td>
<td>
    <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button" /></td>
</tr>
</table>
</form>



      </div>

    </div>

  </div>

</div>


<!-- FOOTER: Site footer for links, copyright, etc. -->
<div id="footer">

  <div id="width">
    <span class="floatLeft">
      design <a href="http://fullahead.org" title="Goto Fullahead">Fullahead</a> <span class="grey">|</span>
      valid <a href="http://validator.w3.org/check?uri=referer" title="Validate XHTML">XHTML</a> <span class="grey">|</span>
      should be valid <a href="http://jigsaw.w3.org/css-validator" title="Validate CSS">CSS</a>
    </span>

    <span class="floatRight">
      <a href="index.html" title="Introduction">intro</a> <span class="grey">|</span>
      <a href="help.html" title="Learn how to use the template">help</a> <span class="grey">|</span>
      <a href="tags.html" title="View the styled tags">tags</a> <span class="grey">|</span>
      <a href="print.html" title="View the print layout">print</a> <span class="grey">|</span>
      <a href="http://fullahead.org/contact.html" title="Get in touch">mail</a>
    </span>
  </div>

</div>

</body>

</html>

the default.aspx.cs part of the coding:

using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.OleDb;



public partial class _Default : System.Web.UI.Page 
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void check() { 
    
    
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        string path=Server.MapPath("App_Data");
        string path2 = Server.MapPath("admin.aspx");
        
        string username = TextBox1.Text.ToString();
        string password = TextBox2.Text.ToString();
        
        String myConn = "Provider=Microsoft.JET.OLEDB.4.0;Data Source='"+path+"\\user.mdb';";
       
        String myQuery = "SELECT password FROM users WHERE username='"+username+"'";

        OleDbConnection cn = new OleDbConnection(myConn);
        cn.Open();
       
        OleDbCommand cmd = new OleDbCommand(myQuery, cn);
        
        OleDbDataReader read = cmd.ExecuteReader();
        while (read.Read())
        {
            if (password == read.GetString(0))
            {
                //WHAT AM I GOING TO PUT HERE?????
              
             

            }
          


        }

      
        cn.Close();    
       
    }
}

I must say thanks in advance if you need anything more to understand the code please ask...Thanks in advance.....

Recommended Answers

All 2 Replies

Thank you...However back to my first question how can i forward the person who got the password and the username correct to admin.aspx??

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.