ASP. NET site navigation (3)

Source: Internet
Author: User

If there are many page files (aspx pages) on the website, I will put the files in different folders. I do not know what to put the files in different folders, haha. I usually share the following points: 1. Place the page files that jointly complete a function in the same folder; second, according to the user's access restrictions (users of different roles can access different files ).

I have nothing to do over the past few days, so I will refer to the ideas of my predecessors in the garden and write two examples of website navigation. If I want to use website navigation controls for other projects in the future, I am familiar with it.

I. ASP. NET site navigation Example 1

The Web is used directly here. sitemap: Write the file link in sitemap, and configure the role access restrictions for different pages (using the roles attribute of sitemapnode), Web. the following restrictions are also imposed in config:

Code
<! -- Parent1: the user In Role 0 , 2 -->
< Location Path = " Parent1 " >
< System. Web >
< Authorization >
< Allow roles = " 0, 2 "   />
< Deny users = " * "   />
</ Authorization >
</ System. Web >
</ Location >

The restriction is also imposed in Web. config to restrict users without the "" role to access any files in the parent1 folder. This is exactly the same as displaying files in the parent1 folder in the navigation control (Treeview \ menu, users who do not have the "" role can see the file link in the parent1 folder (this is because the role is specified in the roles attribute of the sitemapnode node in sitemap, I add this file link node to the navigation control according to this role), but I cannot access this file and "cannot find it", hey.

Advantages:

1. You can use all navigation controls without writing anyCode

2. Site maps allow you to easily use local resources (in multiple languages)

3. Combined with roleprovider, you can easily manage user role restrictions.

4. Do not need to write custom site maps to provideProgramUse the default system. Web. xmlsitemapprovider.

Disadvantages:

Because the navigation control is placed on the master page, if there are too many files and the master page needs to be loaded each time, the site map must be reloaded, which will consume resources?

However, in this example, I did not use the menu control. in example 2, I wrote the menu.

Source code: Demosolution1.rar

Ii. ASP. NET site navigation Example 2

I did not use web. sitemap here, but directly linked the file to the database based on the ideas of the predecessors. The database structure is as follows:

These fields in the Treeview table should be enough. I don't know what fields to add. It should be enough.

Advantages:

1. Because all file link data exists, the database does not need to provide site maps.

2. You do not need to write a custom site map provider configuration file or the sitemap node (system. Web. xmlsitemapprovider)

3. Nodes in Treeview or menu are implemented by code. Combined with roleprovider, you can easily manage user role restrictions.

Disadvantages:

1. The sitemappath control cannot be used directly.

2. Because the navigation control is placed on the master page, if there are too many files, the master page should be loaded every time and node data should be retrieved from the database, which is a waste of resources. Consider

Use data cache, or make a control, and then use the control cache (page cache );

3. Because data is stored in a data table, special maintenance is required, which is also troublesome.

4. The site map file is stored in the database and you do not know how to use the localized resources (in multiple languages)

Source code: demosolution2.rar

Iii. ASP. NET site navigation Example 3

This is actually an example on Microsoft's msdn, using a flat file (txt file) as a site map. Then write your own site map provider, inherit

FromSitemapprovider,However, role management is not provided in this example, and I am still studying it.

Advantages:

1. You can use all navigation controls without writing any code.

Disadvantages:

1. The site map is a TXT file. I don't know how to use the localized resources (in multiple languages)

2. How to Use roleprovider to manage user role restrictions?

3. Because the custom site map provider needs to declare the sitemap node (type = "demosolution. simpletextsitemapprovider") in the configuration file ")

4. During the test, I found that every time I add a node to the TXT file, I need to modify the sitemapfile attribute of the sitemap node in the configuration file (for example, the original sitemapfile = "simpletextsitemapprovider/sitemap.txt" example, then, when you browse the page, you will not be able to find the file, and then change the name back. Why)

Source code: demosolution3.rar

Iii. ASP. NET site navigation Example 4

This is also an example of Microsoft's msdn. Like example 2, the file link is stored in the database. I have rewritten the msdn example and stored the data in SQL.

Server2005 is in progress. Then I wrote my own site map provider, inherited fromStaticsitemapprovider,This example is also not mentioned.

Supply AngleColorManagement.

Database Structure:

Advantages:

1. You can use all navigation controls without writing any code.

Disadvantages:

1. The site map file is stored in the database and you do not know how to use the localized resources (in multiple languages)

2. How to Use roleprovider to manage user role restrictions?

3. Because the custom site map provider needs to declare the sitemap node (type = "demosolution. sqlsitemapprovider") in the configuration file ")

4. During the test, I also found that every time I add a node to the database, I need to modify the type attribute of the sitemap node in the configuration file, such as the original

Type = "demosolution. sqlsitemapprovider", I changed it to type = "demosolution. sqlsitemapprovider1", and then

An error will be reported when you view the page and change the name back. Why ???

5. I found that the Treeview control can only display one root node. I don't know what went wrong ????

Source code: demosolution4.rar

Msdn:

Dataview class

A custom view that can be bound to data for sorting, filtering, searching, editing, and navigation.

DataviewAllows data binding on Windows and web forms.

In addition, it can be customized.DataviewTo represent the subset of data in the able. This feature allows you to have two controls bound to the same able but displaying different data versions. For example, a control may be boundDataviewThe other control may be configured to display only the rows that have been deleted from the datatable. Datatable also has the defaultview attribute. It returns the default value of the table.Dataview. For example, if you want to create a custom view on a tableDataviewSet rowfilter.

To create a data filtering and sorting view, set the rowfilter and sort attributes. Then, a single datarowview is returned using the item attribute.

You can also use the addnew and delete methods to add and delete rows from the collection. When using these methods, you can set the rowstatefilter attribute to specify that only deleted rows or new rows can beDataviewDisplay.

Note:

If you do not explicitly specifyDataviewAccording to the corresponding dataviewDatarowInDatatable. RowsDatarowcollectionToDataviewInDatarowviewSort objects.

LINQ to dataset allows developers to use LINQ to create complex and powerful queries to dataset. The Data Objects of the datarow object are returned for the LINQ to dataset query, but it is not easy to use in the binding scheme. Dataview You can create a query from the LINQ to dataset interface and have the filtering and sorting features of the query. By providing filtering and sorting based on LINQ expressions (performing filtering and sorting operations that are more complex and more powerful than string-based filtering and sorting operations), LINQ to dataset can be expanded Dataview . For more information, see .

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.