Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 224
  • Last Modified:

login control

Hi Expert,
I use login control in the login page. When I run in
the Visual IDE, it starts with login page. Then I type usernam, and
password. If it passes, I go to the other page (called dialcode.aspx).
However if i run in the browser (firefox), it always go to my dialcode page.
Could you help?
Thx,
JT
0
jtran007
Asked:
jtran007
  • 9
  • 8
  • 3
  • +1
3 Solutions
 
urir10Commented:
Is your web.config file set to redirect the user if the user is not logged in?
		<authentication mode="Forms">
			<forms loginUrl="login.aspx" protection="All" timeout="180" name=".ASPXAUTH" path="/" requireSSL="false" slidingExpiration="false" defaultUrl="~/Default.aspx" cookieless="UseDeviceProfile"/>
		</authentication>
		<authorization>
			<deny users="?"/>
		</authorization>

Open in new window

0
 
jtran007Author Commented:
Hi expert,

How is web.config working; since I am new to web app.
Thx,
JT
0
 
urir10Commented:
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
jtran007Author Commented:
Hi expert,
I copied your attached code, and put into my web.config. It's not working; it did not
allow me to go to another page either.

What do I have to change your code?
Thx,
JT
0
 
jtran007Author Commented:
Hi expert,
Attached is my added in the web.config.When I click login,
nothing happens.

Please help.
Thx,
JT
 <authentication mode="Forms">
 
      <forms loginUrl = "Login.aspx" name="3345C" timeout="1"/>
 
    </authentication>

Open in new window

0
 
guru_samiCommented:
Can you share the code how you are authenticating the user?
Are you using Membership Provider?
Make sure browser cookies is enabled.
Are you having any roles?

Please share all relevant code.
0
 
jtran007Author Commented:
Hi expert,
Yes, I can.
No I am using membership provider.
What are cookies for?
No I don't have any roles.
Just create user name, and password. And let them
use my web app. That's all ai want.
Thx,
Jt
        protected void Login1_Authenticate1(object sender, AuthenticateEventArgs e)
        {
            bool Authenticated = false;
            Authenticated = Authenmethod(Login1.UserName, Login1.Password);
            e.Authenticated = Authenticated;
            if (Authenticated == true)
            {
                Response.Redirect("dialcode.aspx");
            }
 
        }
        private bool Authenmethod(string UserName, string Password)
        {
            if (UserName.Equals("qiiq") && Password.Equals("abc"))
                return true;
            else
                return false;
        }

Open in new window

0
 
guru_samiCommented:
----What are cookies for?
FormsAuthentication requires cookies enabled by default...So check you browers accept cookies...
With FireFox .. Got to Tools->Options->Privacy Tab -> Make sure Accept cookies from site Checkbox is Selected.

Might sound stupid to ask...but make sure you are entering correct username and password...i.e. by mistake you are not entering leading or trailing spaces....

Also Drag and drop LoginName and LoginStatus control on your Login.aspx page for troubleshooting purpose.
0
 
guru_samiCommented:
Oh yeah also make sure you are denying anonymous access to your website ...i.e. add this to your web.config:

<authentication mode="Forms">
   <forms loginUrl = "Login.aspx" name="3345C" timeout="1"/>
    </authentication>
<authorization>
      <deny users="?"/>
    </authorization>
0
 
jtran007Author Commented:
Hi expert,

Yes I did include it in the web.config.
Somehow I run in the Visual IDE, it's workin fine but not
in the browser.

Thx,
JT
0
 
urir10Commented:
There is one problem i found with your code.
You have e.Authenticated = Authenticated;    outside the if statement so the user is always Authenticated= true.
Do it like that
 protected void Login1_Authenticate1(object sender, AuthenticateEventArgs e)
        {
            bool Authenticated = false;
            Authenticated = Authenmethod(Login1.UserName, Login1.Password);
            
            if (Authenticated == true)
            {
                e.Authenticated = Authenticated;
                Response.Redirect("dialcode.aspx");
            }
 
        }
        private bool Authenmethod(string UserName, string Password)
        {
            if (UserName.Equals("qiiq") && Password.Equals("abc"))
                return true;
            else
                return false;
        }

Open in new window

0
 
jtran007Author Commented:
Hi expert,

guru_sami:
I did check Firefox.its setting is ok as you said.
Also in the web.config, I do include .
But the result is still the same.

Thx,
JT
0
 
guru_samiCommented:
Hmm.. Lets see it again....
When you say:
"However if i run in the browser (firefox), it always go to my dialcode page."
Does same thing happens when you try it in IE?
Do you mean after logging or directly to dialcode.aspx without logging-in?
Did you try placing LoginName Control on your Login.aspx page? What do you see when you start your website first.
Can you also place a LoginName control on your dialcode page and let us know what you see.
 
0
 
jtran007Author Commented:
Hi expert,
No, when I run in IDE, the login starts first. Then if the authentication is OK,
user is allowed to the other page.
The logging happens only in the login page, not in the dialcode page.
The result I told you so far is that login control is in the login page .
If you want to try login control in the dialcode page, I'll do. But not my
intention.

Regards,
JT
0
 
guru_samiCommented:
I think you misunderstood about LoginName control...
Login Control and LoginName Control are two different control.
So I am suggesting you to place LoginName control in your Login.aspx(which also has Login Control)
and your Dialcode.aspx(which will have just LoginName control and not Login control).

Check this: http://www.dotnetjunkies.ddj.com/QuickStartv20/aspnet/doc/ctrlref/login/loginname.aspx
0
 
guru_samiCommented:
and when I say:
Does same thing happens when you try it in IE?

I mean Internet Explorer (IE) as you mentioned firefox specifically so just wondering if it is working fine with IE.
0
 
jtran007Author Commented:
Hi expert,

Since I have a  lot of controls in the dialcode page. Now I put login control in this page, other
controls must be disabled, and enable when authentication is verified.
Is it possible to have login in the login page, and my othe controls in the dialog page?
Thx,
JT
0
 
guru_samiCommented:
Did you get my last post....I still confirm ...login Control and LoginName control are two different controls.
0
 
jtran007Author Commented:
Hi expert,

I did get your last post; however I went home at 5:30PM. Now I return your
post from home. How do I use login control name?

Thx,
JT
0
 
guru_samiCommented:
just drag and drop LoginName control from VS Toolbox on your Login.aspx and dialcode.aspx.
Thats it nothing else. No coding.
The reason for using this is I just want to make sure if there is session alive and you are staying logged-in somehow.
0
 
M3mph15Commented:
Hi,

What you could do is add a variable to the session when they login.....for example their username or somethign like that.

E.g. String usr = <username> ;
         Session.Add('AuthUser', usr); //AuthUser is the name of the object in the session, it can be changed to whatever suits you. usr is the name of the variable we are adding to the session.

Then in the Page_Load method of dialcode.aspx check if the variable in the session exists. If so then the user has logged in. If not then either the user has not logged in or the session has expired so redirect them to the login page.

string usr = Session("AuthUser");
if usr = null or usr.Length = 0 then
{
         Response.Rediect("Login.aspx");
}

Syntax may be a bit off....coding off the top of my head....not at a computer where i can test this.

That way the user will not be able to access the page without logging in. This can be used in any page the same way.

HTH
-M3mph15
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 9
  • 8
  • 3
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now