Solved

Forms Authentication roles not working

Posted on 2014-10-01
2
90 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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

757 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

17 Experts available now in Live!

Get 1:1 Help Now