Brockmann: "Creating Rich Web
Applications Gets a Ton Easier"

e-grou chooses Visual WebGui
over standard ASP.NET

Quick migration of VB 6.0
Applications to the Web

Fully functional software versions
for 30 days evaluation period

Download the free edition of the
Visual WebGui Studio
 

Code Snippets

tamir.zaslavsky posted on November 01, 2007 :: 3662 views

Visual WebGui provides simple way to implement Logon screen.  Adding 'Authentication' element in the web.config file, send the user to the page specified in that element if he/she is not logged on.

<Authentication Mode="Main" Type="Gizmox.WebGUI.Sample.Forms.Logon, Gizmox.WebGUI.Sample" />

Currently the only supported Mode (notice Mode attribute) is Main. In the future we'll also implement Dialog mode.

Jconstantino and rhernandez_64 asked for this feature in this post. Although this feature isn't in our roadmap for the near future, its functionality can be achieved relatively easily. Here are two simple steps you need to take in order to implement a dialog logon screen:

1.     Move all the code in the "Form_Load" method of your main form to new method that will be called after the user successfully logged on. Instead if the user is not logged on you should show a dialog popup screen:

Old code:

private void MainForm_Load(object sender, EventArgs e)
      {
            InitializeData();
            Foo();

}

 

New code:

private void MainForm_Load(object sender, EventArgs e)
      {

//if user is not logged on - show logon screen
      if (!Context.Session.IsLoggedOn)

{

                  Logon objLogonPopup = new Logon();

objLogonPopup.Closed += new EventHandler(objLogonPopup_Closed);
objLogonPopup.ShowDialog();
}

}

private void FormLoad_AfterLogon()
      {
            InitializeData();
            Foo();
            }

2.     Create a logon form. And set Context.Session.IsLoggedOn (Boolean) accordingly. If user logged on successfully, then close the form. Else alert the user:

private void btnLogon_Click(object sender, EventArgs e)
      {
            Context.Session.IsLoggedOn = (txtPassword.Text == "pass1" &&

txtUsername.Text == "user1");

            if (Context.Session.IsLoggedOn)
            {
                this.Close();
            }
            else
            {
                MessageBox.Show(    "Username or Password inocrrect!",

"Login Faild",

MessageBoxButtons.OK,

MessageBoxIcon.Error);

}

}

You can download the sample application attached...

That's it, enjoy!

Tamir Zaslavsky

Download Code

Note: Codes are submitted as a .zip file to shorten your download time. After downloading it, you will need a program like Winzip to decompress it.

Terms of Agreement:
By using this code, you agree to the following terms...

  1. You may use this code in your own programs (and may compile it into a program and distribute it in compiled format for languages that allow it) freely and with no charge.
  2. You MAY NOT redistribute this code (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.
  3. You may link to this code from another website, but ONLY if it is not wrapped in a frame.
  4. You will abide by any additional copyright restrictions which the author may have placed in the code or code's description.

Post Rating

Comments

There are currently no comments, be the first to post one.

Post Comment

Only registered users may post comments.
Most promising startups
Top 3 most promising startups in 2009
   AJAX Framework | Web Development | Cloud applications | RIA Development | Silverlight Applications | Legacy Migration
The most popular open source Ajax applications framework for enterprises | Sitemap | Terms Of Use | Privacy Statement
Copyright © 2005-2009 Visual WebGui®    Design By: Template World
   
Visual Studio Partners