Solved

Forms Authentication roles not working

Posted on 2014-10-01
2
97 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

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

Sometimes in DotNetNuke module development you want to swap controls within the same module definition.  In doing this DNN (somewhat annoyingly) swaps the Skin and Container definitions to the default admin selections.  To get around this you need t…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
This video shows how to use Hyena, from SystemTools Software, to update 100 user accounts from an external text file. View in 1080p for best video quality.

752 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