Solved

Forms Authentication roles not working

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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Lots of people ask this question on how to extend the “MembershipProvider” to make use of custom authentication like using existing database or make use of some other way of authentication. Many blogs show you how to extend the membership provider c…
I have developed many web applications with asp & asp.net and to add and use a dropdownlist was always a very simple task, but with the new asp.net, setting the value is a bit tricky and its not similar to the old traditional method. So in this a…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

828 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