Membership - Log Out Programatically

M

Mick Walker

Hi All,

I have a situation where I am using a login control to log a user in to
my web app.
Under the LoginButton_Click handler of the login control, I retrive some
custom user information from the database.
Based on this information, the situation may arise where I want to log
the user out automatically even if a valid username/password has been
entered in the login control.

I have tried using:
Session.Abandon()
FormsAuthentication.SignOut()
and this doesnt seem to work, does anyone have any ideas how I can
acomplish a logout via code?

Regards
Mick
 
M

Mick Walker

Mick said:
Hi All,

I have a situation where I am using a login control to log a user in to
my web app.
Under the LoginButton_Click handler of the login control, I retrive some
custom user information from the database.
Based on this information, the situation may arise where I want to log
the user out automatically even if a valid username/password has been
entered in the login control.

I have tried using:
Session.Abandon()
FormsAuthentication.SignOut()
and this doesnt seem to work, does anyone have any ideas how I can
acomplish a logout via code?

Regards
Mick
Oh I forgot to mention I am using Forms Authentication, here is the
relevent info from my web.config
<membership defaultProvider="CustomizedProvider">
<providers>
<add name="CustomizedProvider"
type="System.Web.Security.SqlMembershipProvider"
connectionStringName="SDConn" minRequiredPasswordLength="5"
minRequiredNonalphanumericCharacters="0"/>
</providers>
</membership>
<roleManager enabled="true" defaultProvider="CustomizedRoleProvider">
<providers>
<add connectionStringName="SDConn" name="CustomizedRoleProvider"
type="System.Web.Security.SqlRoleProvider"/>
</providers>
</roleManager>
<authentication mode="Forms"/>
 
A

Alexey Smirnov

Oh I forgot to mention I am using Forms Authentication, here is the
relevent info from my web.config
<membership defaultProvider="CustomizedProvider">
<providers>
<add name="CustomizedProvider"
type="System.Web.Security.SqlMembershipProvider"
connectionStringName="SDConn" minRequiredPasswordLength="5"
minRequiredNonalphanumericCharacters="0"/>
</providers>
</membership>
<roleManager enabled="true" defaultProvider="CustomizedRoleProvider">
<providers>
<add connectionStringName="SDConn" name="CustomizedRoleProvider"
type="System.Web.Security.SqlRoleProvider"/>
</providers>
</roleManager>
<authentication mode="Forms"/>- Hide quoted text -

- Show quoted text -

Maybe change the role of a user could help you here?
 
M

Mick Walker

Alexey said:
Maybe change the role of a user could help you here?
I can't see how this would help me to be honest. At present I only have
two roles. User and Moderator.

Could you elaborate please?
 
F

fredd00

I can't see how this would help me to be honest. At present I only have
two roles. User and Moderator.

Could you elaborate please?

you could create a 3rd role like 'lockedout' and deny this role the
rights to view content
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top