Have you checked the User.Identity.Name and the user name you are providing ?
Have you checked your web.config file ?
regards,
Ramkumar
Main Topics
Browse All TopicsI am developing a website in Visual Studio 2005 using ASP.NET 2.0 technology. Using the Web Site Administration Tool, I have changed the website to use Forms Authentication, created a few users, turned on Roles, and created a couple of roles which I then assigned to the users.
Now on my web form I placed the ASP.NET Login control on the form. It works perfectly and I can login and logout and everything. My problem is that once the user has logged in, I want to check which role he is in so that I know where to redirect him. I use the following code in the Login1_Authenticate event (Login1 is the name of the Login control):
Select Case True
Case User.IsInRole("Teacher")
Response.Redirect("~/Teach
Case User.IsInRole("Parent")
Response.Redirect("~/Paren
Case User.IsInRole("Student")
Response.Redirect("~/Stude
End Select
But it goes right through the Select Case block without any of the cases being true. Now those are the only roles I have defined, and every user belongs to one of those roles, so one of them should be true! I tried moving the code to the Login1_LoggedIn event rather, but same problem. I even tried it on the Page_Load event and nothing. If I check the User.Identity.IsAuthentica
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
hi SETP
Authenticate event provides you with the custom authentication method to define. Do not use the Authenticate method, and delete the cross-reference from your HTML tags where it says something like this:
<asp:Login ID="Login1" OnAuthenticate="Login1_Aut
delete OnAuthenticate entry kind of stuff
Now next part, put your code in Login1_LoggedIn. This is the event which gets executed on successful login.
let me know if you still have problem with redirecting.
Happy Programming ;)
Hi awabid. I put the code under the Login1_Authenticate event, but same problem. I also removed all HTML code refering to Login1_Authenticate.
Ramkumar, I'm definitely typing in the correct username and password. However, when I check User.Identity.Name it is showing up blank (empty string or nothing, not sure), as is User.Identity.Authenticati
This is what my web.config file looks like (I've removed only the comments):
<?xml version="1.0"?>
<configuration xmlns="http://schemas.micr
<appSettings/>
<connectionStrings/>
<system.web>
<roleManager enabled="true" />
<compilation debug="true" strict="false" explicit="true"/>
<pages>
<namespaces>
<clear/>
<add namespace="System"/>
<add namespace="System.Collecti
<add namespace="System.Collecti
<add namespace="System.Configur
<add namespace="System.Text"/>
<add namespace="System.Text.Reg
<add namespace="System.Web"/>
<add namespace="System.Web.Cach
<add namespace="System.Web.Sess
<add namespace="System.Web.Secu
<add namespace="System.Web.Prof
<add namespace="System.Web.UI"/
<add namespace="System.Web.UI.W
<add namespace="System.Web.UI.W
<add namespace="System.Web.UI.H
</namespaces>
</pages>
<authentication mode="Forms" />
</system.web>
</configuration>
As you can see, there is no user or role information in there, but I guess that's because it's all stored in the SQL database?
The problem is there with your web.config
<authentication mode="Forms" />
the following link definitely solves your problem:
http://www.supinfo-project
regards,
Ramkumar
well, i modified my web.config file but same problem. This is what it looks like now:
<?xml version="1.0"?>
<configuration xmlns="http://schemas.micr
<appSettings/>
<connectionStrings>
<add name="MyLifeConnectionStri
connectionString="Data Source=FABRICIO-PC\SQLEXPR
providerName="System.Data.
</connectionStrings>
<system.web>
<membership defaultProvider="Membershi
<providers>
<add name="MembershipSqlProvide
type="System.Web.Security.
connectionStringName="MyLi
applicationName="MyLife"/>
</providers>
</membership>
<roleManager enabled="true" defaultProvider="RoleManag
<providers>
<add name = "RoleManagerSqlProvider"
type="System.Web.Security.
connectionStringName="MyLi
applicationName="MyLife"/>
</providers>
</roleManager>
<compilation debug="true" strict="false" explicit="true"/>
<pages>
<namespaces>
<clear/>
<add namespace="System"/>
<add namespace="System.Collecti
<add namespace="System.Collecti
<add namespace="System.Configur
<add namespace="System.Text"/>
<add namespace="System.Text.Reg
<add namespace="System.Web"/>
<add namespace="System.Web.Cach
<add namespace="System.Web.Sess
<add namespace="System.Web.Secu
<add namespace="System.Web.Prof
<add namespace="System.Web.UI"/
<add namespace="System.Web.UI.W
<add namespace="System.Web.UI.W
<add namespace="System.Web.UI.H
</namespaces>
</pages>
<authentication mode="Forms" />
</system.web>
</configuration>
This is what your web.config requires
< authentication mode="Forms" >
< forms loginUrl="login.aspx" name=".ASPXFORMSAUTH" >
< / forms >
< / authentication >
But you have added unwanted things to your web.config file.
You can also refer this link http://www.exforsys.com/co
regards,
Ramkumar
Added that but still not working. This is what it looks like now:
<?xml version="1.0"?>
<configuration xmlns="http://schemas.micr
<appSettings/>
<connectionStrings>
<add name="MyLifeConnectionStri
connectionString="Data Source=FABRICIO-PC\SQLEXPR
providerName="System.Data.
</connectionStrings>
<system.web>
<membership defaultProvider="Membershi
<providers>
<add name="MembershipSqlProvide
type="System.Web.Security.
connectionStringName="MyLi
applicationName="MyLife"/>
</providers>
</membership>
<roleManager enabled="true" defaultProvider="SqlProvid
<providers>
<add connectionStringName="MyLi
name="SqlProvider" type="System.Web.Security.
</providers>
</roleManager>
<compilation debug="true" strict="false" explicit="true"/>
<pages>
<namespaces>
<clear/>
<add namespace="System"/>
<add namespace="System.Collecti
<add namespace="System.Collecti
<add namespace="System.Configur
<add namespace="System.Text"/>
<add namespace="System.Text.Reg
<add namespace="System.Web"/>
<add namespace="System.Web.Cach
<add namespace="System.Web.Sess
<add namespace="System.Web.Secu
<add namespace="System.Web.Prof
<add namespace="System.Web.UI"/
<add namespace="System.Web.UI.W
<add namespace="System.Web.UI.W
<add namespace="System.Web.UI.H
</namespaces>
</pages>
<authentication mode="Forms" >
<forms loginUrl="Login.aspx" name=".ASPXFORMSAUTH" >
</forms>
</authentication>
</system.web>
</configuration>
Well, still don't know what the problem is, but I managed to solve it a different way:
Select Case True
Case Roles.IsUserInRole(Login1.
Response.Redirect("~/Teach
Case Roles.IsUserInRole(Login1.
Response.Redirect("~/Paren
Case Roles.IsUserInRole(Login1.
Response.Redirect("~/Stude
End Select
This approach seems to work. I don't know why I can't use User.IsInRole. Anyways, thanks for your help guys. I've split the points between the two of you.
Business Accounts
Answer for Membership
by: netswapPosted on 2006-08-02 at 03:18:22ID: 17231637
Hi SETP,
Then er.aspx")
t.aspx")
nt.aspx")
replace case with if...elseif ladder as under, other all are right.
if (User.IsInRole("Teacher"))
Response.Redirect("~/Teach
else if (User.IsInRole("Parent")) Then
Response.Redirect("~/Paren
else if (User.IsInRole("Student"))
Response.Redirect("~/Stude
end if
Regards,
NetSwap