Solved

Forms Authentication roles not working

Posted on 2014-10-01
2
92 Views
Last Modified: 2014-10-13
Hi, I have the code below that adds a user to a role after finding them in a database and is supposed to redirect to another page or the default. This does not seem to be happening and I am not sure why. It doesnt show an error but looks like it posts back to itself

FormsAuthentication.RedirectFromLoginPage(TextBox2.Text, False)

            If Not Roles.RoleExists("Admin") Then
                Roles.CreateRole("Admin")
            Else
                If Roles.IsUserInRole("Admin") Then
                    'do nothing
                Else
                    Roles.AddUserToRole(TextBox2.Text, "Admin")
                End If
            End If

Open in new window


My web.config is as follows;

  <location path="Admin">
    <system.web>
      <authorization>
        <allow roles="Admin"/>
        <deny users="*"/>
      </authorization>
    </system.web>
  </location>

Open in new window


<modules runAllManagedModulesForAllRequests="false">
      <remove name="FormsAuthenticationModule" />
      <add name="FormsAuthenticationModule" type="System.Web.Security.FormsAuthenticationModule" />
      <remove name="UrlAuthorization" />
      <add name="UrlAuthorization" type="System.Web.Security.UrlAuthorizationModule"  />
      <remove name="RoleManager" />
      <add name="RoleManager" type="System.Web.Security.RoleManagerModule" />
      <remove name="DefaultAuthentication" />
      <add name="DefaultAuthentication" type="System.Web.Security.DefaultAuthenticationModule" />
    </modules>

Open in new window

0
Comment
Question by:takwirirar
2 Comments
 
LVL 26

Accepted Solution

by:
Shaun Kline earned 500 total points
ID: 40357698
For the logic you are displaying in the first code block, is the following accurate?

You have a page that allows you to add users to a role (which I'm guessing is lines 3-11).
You are then testing when a user with admin permissions logs in (line 1), they are redirected to the page that requires admin permissions.

When you do this, are you confirming the user was added to the role in your database for your application? What membership provider are you using?
0
 
LVL 1

Author Closing Comment

by:takwirirar
ID: 40377323
Shaun, I ended up creating a subdomain for admins and hosting it separately in IIS i.e. users.x.com and admin.x.com. Thanks
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now