E
E
Eugene2021-11-23 17:59:39
ASP.NET
Eugene, 2021-11-23 17:59:39

How to make authorization by roles?

Created a standard ASP.NET web application. A couple of pages + authorization are already being created there.
How to do it: so that when you open the site, a window with authorization opens, and then goes to the main site.
I did the following. Created a Web.sitemap and wrote this code there:

web.sitemap:
<siteMapNode url="Contact.aspx" title="Контакт"  description="" roles="User" />


I also added these lines to Web.config:
Web.config:
<location path="Contact.aspx">
    <system.web>
      <authorization>
        <allow roles="User"/>
        <deny users="*"/>
      </authorization>
    </system.web>
  </location>


After adding these lines, I turned on the site and registered to create a SQL database.
Then I went to the "Server Explorer" tab. The same SQL database was created there.
In the table of this database, I went to the Roles section, and added the role there, User.
And when I went to the Contact.aspx page, it was thrown into authorization.
But even after authorization, they didn’t let me into Contact.aspx.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
Eugene, 2021-11-25
@Big_PixeL

I found a solution! The point is. We create an ASP.NET web application with built-in authorization from Microsoft (not a blank web application). Then we go to the top of the Visual Studio screen, and there we see the "Project" button (Someone may call it Web Project), click and select the "ASP.NET Configuration" item. Your browser will open with the ASP.NET Web Site Administration Tool page. There we go to the "Security" tab, and there will be the "Roles" field in the center, click "Enable". After that, the roles will work. Now click on "Create and manage roles", and add the desired role. For example "Admin". After that, you can safely register on your site, and return to these settings again. There you can find your registered account by name.
Attention! Nothing then needs to be changed or added to the SQL database, which was automatically created, and about which I wrote at the beginning, I made a mistake then. You just need to configure everything through the "Web site administration tool". Thanks to everyone who tried to help. And I hope this information helps someone.

[A photo].
619f7dd422309387771392.png

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question