Forum  General Visual ...  How do I...?  Redirect in a form's Load event
Previous Previous
 
Next Next
New Post 11/4/2007 8:54 AM
  fisherman
163 posts
5th Level Poster


Redirect in a form's Load event 

I have a BaseForm with code like

        private void frmBase_Load(object sender, EventArgs e)
        {
            if (!DesignMode)
            {
                HttpSessionState aSession = this.Context.HttpContext.Session;
                if ((aSession["userid"] == null) || ((int)aSession["userid"] < 1))
                {
                    this.Context.Redirect("login.wgx");
                }
            }
        }

I want to inherit all other forms from this form, so that the login form is automatically displayed if the user is not logged in or has no valid user ID, even if the user enters a URL (wgx)  manually.
But it seems that redireting in the Load event does not work correctly. The background color of my login form is displayed, but all controls (button, textbox) are missing.

What am I missing here?
Apart from the incorrect behaviour - should I follow a different approach here ?

Bernhard
 
New Post 11/5/2007 2:20 AM
  tamir.zaslavsky
57 posts
No Ranking


Re: Redirect in a form's Load event 
Modified By tamir.zaslavsky  on 11/5/2007 5:22:12 AM)
Hi Bernhard.
You're right. We have an open Bug "Redirect not working on Form_Load" (VWG-849).

About the approach, I would suggest a different one.
VWG already provide you simple way for implementing login scenario:
1.    Add the following element to web.config (you probably already have it in comment):
<Authentication Mode="Main" Type="YourNamespace.YourLogonForm, YourAssembly" />
 
2.    Implement the logon form. When you want to specify that user has successfully authenticated just set IsLoggedOn property of the current session to 'true': this.Session.IsLoggedOn = true;
 
3.    If you want a "logout" button or link, add it (link or button) and on it click event set the same property to false: this.Session.IsLoggedOn = false;
In general, I would recommend that you try to avoid using Redirect method inside VWG application. It is not best practice. Each VWG application has at least one entry point. When you navigate in your browser to URL that is mapped to an entry point (the mapping is in web.config via Application elements) it's like you "open" a new instance of a desktop application. In your case, if you'll redirect to "login.aspx" that’s mean that you mapped this URL to some form, probably: <ApplicationCode="login"Type="MyApplication.LoginForm, MyApplication "/>. So what you are actually doing is creating new VWG context (which is the equivalent to opening new instance of your application).
We're familiar with the need of developers to "replace" the current form with other form, usually it's for implementing logon screen. That why we added way back the authentication support in web.config.
But there are also other cases that suites this solution. So it’s a good opportunity to announce one of our new features to our next release (5.83): new method will be added to
Gizmox.WebGUI.Forms. Form: Form.Transfer(Form formToReplaceWith). This method receives instance of the form you want to replace with. For example:
           HttpSessionState aSession = this.Context.HttpContext.Session;
            if ((aSession["userid"] == null) || ((int)aSession["userid"] < 1))
            {
                LoginForm form = new LoginForm();
                this.Transfer(form);
            }         
Regards,
Tamir
 
New Post 11/5/2007 5:55 AM
  fisherman
163 posts
5th Level Poster


Re: Redirect in a form's Load event 

Tamir,

thanks for your hints, I appreciate your detailed eplanation.

I see that I'll have to wait for 5.83, because this is exactly what I need. The login form was an example, but having the transfor(form) functionality will make life easier especially for more complex scenarios. I found out that several tabs on a tab sheet are fine if you don't have too many of them, and as long as the logic of switching is not too complicated. The same applies to dynamically creating user controls. So I'm really looking forward to this next version.

Bernhard

 
New Post 11/6/2007 11:46 PM
  itzik.spitzen
1659 posts
1st Level Poster




Re: Redirect in a form's Load event 
Hi Bernhard,

FYI, build 5.83 is planned to be released at the end of November 2007.

Regards,
Itzik Spitzen
 
Previous Previous
 
Next Next
  Forum  General Visual ...  How do I...?  Redirect in a form's Load event
Assessment Bottom
.NET Web, Cloud and Mobile application delivery platform | Sitemap | Terms of Use | Privacy Statement | Copyright © 2005-2011 Visual WebGui®       Visual WebGui weblog on ASP.NET Visual WebGui Group on LinkedIn Visual WebGui updates on Twitter Visual WebGui Page on Facebook Visual WebGui YouTube Channel Visual WebGui Platform News RSS