Custom web site administration tool
In he third part with the help of a grid you can lists users and some of their profile properties. For the alphabet bar I used a Repeater control, instead of a fixed list of links. To this Repeater control I bounded an array of characters that will finally be displayed as links. So, if later you want to remove certain characters from your alphabet bar, you will only have to remove those letters from that array.
The third part of the page contains a Gridview that will lists users and some of their properties. All we need is to specify the number and the type of columns for this grid.
Below you will find the description for each column:. For the username, the creation date and last access date we will use BoundField columns. These values for these data will be displayed as strings.
For user's e-mail use a HyperLinkField to show the as an active link that uses the mailto: protocol. To redirect the administrator to a page called EditUsers. This link will have the username as a querystring value and will allow the administrator to edit a user's profile. To delete a user use a ButtonField column to create a graphical Delete button.
To do this set the column's ButtonType property to "Image". This new feature was introduces only for ASP. In the page's code-behind file there is MemershipUserCollection object. This object is initialized with all the user information returned by Membership. GetAllUsers static method. In the Load event of this page we will use the Count property of this collection to display the total number of registered users and also the number of online users.
I also created an array that contains letters that will be bound to the Repeater control in order to create the alphabet. ToString ; lblTotalUsers. Split ';' ; rptAlphabetBar. When the administrator will click a letter link, the ItemCommand event of the Repeater control will raise. Here we will retrieve that letter and search for all users with the name that starts with that letter. When you click the All link, the gridview will show all the users.
This search mode is stored in the Attributes collection of the gridview so that it is persisted in the view state, and doesn't get lost during a postback. Here's the code:. Add "SearchByEmail" , false. ToString ; if e. Add "SearchText" , e. Add "SearchText" , "" ; this. In this event the BindAllUsers method is called. The Boolean value that is passed as an input parameter indicates if the allRegisteredUsers collection must be repopulated especially when a user is deleted.
The text to search for and the search mode are retrieved from the grid's Attributes collection. Below is the code:. IsNullOrEmpty gvUsers. Parse gvUsers. Attributes[ "SearchByEmail" ] ; if searchText. This BindAllUsers method is also called when the Search button is clicked. In this case, the search mode will be set according to the value selected in the ddlUserSearchTypes dropdown list control.
If you want to delete a user you have to click the trashcan icon. Inside this event handler you will use the static methods of the Membership and ProfileManager classes to delete the user account and its accompanying profile. BindAllUser method is called with true as a parameter , so that the collection of all users is refreshed, and the new information is displayed:.
ToString ; ProfileManager. DeleteProfile userName ; Membership. If you delete a user you cannot undo this action. This is why you should have the administrator confirm this action before proceeding. Through the button's OnClientClick property you can add a "confirm" JavaScript in the link's onclick client-side event. All these can be done in the gridview's RowCreated event to get a reference to each link as soon as its parent row and all its contents are created.
Controls[0] as ImageButton ; btn. This script is added only for rows of type DataRow. In this way we will avoid to add this script to the header, footer, and pagination bars. After registering every user has to fill in some forms with his profile. Due to flexibility I grouped all these forms and controls into a user control. In this way I can use the same user control in the administration section to edit the profile for a user. So, the profile proprieties that we configured in web.
Please see below the mark-up code for this user control. Profile; if this. GetProfile this. I have written two methods, " allowfolderaccess " and " denyfolderaccess ", using the classic System.
Configuration approach. NET Framework. The fun in using these is that, if you do not want to create your own classes and database structure and still want a strong membership and role management feature in place, you can use the default providers which are inbuilt into the database. A much bigger advantage with this feature is that, if you do not want to use the default classes and default database but want your own database structure, you can modify the entire behaviour of your web application according to your needs.
The only thing you have to take care is that you will have to implement a defined set of interfaces in your class so that the API can use it. Now, how do you do it? Blank functions are created automatically, and the only thing you have to do is fill in the blanks. You can download the code provided with this article and directly copy the code to your machine to check the functionality. To manage the debugging and tracing features, click Configure debugging and tracing , and then set the following options:.
Select this option to enable tracing for all pages in the Web site. If this check box is selected, the remaining options on the page are enabled.
Select this option to append tracing information to the bottom of Web pages on your site. If you do not display tracing information about individual pages, the information is still captured. To view trace information, you can request the Trace. Select this option to view trace information only for request from the host Web server localhost. Under Select the sort order for trace results , specify how you want to display trace information, as follows:.
Enter the number of trace requests to store on the server. The default is If you do not select the Most recent trace results option, and the limit is reached, trace is automatically disabled.
Under Select which trace results to cache , specify how you want to display trace output, as follows:. Select this option to display the most recent trace output and to discard older trace data beyond the limits that are indicated by Number of trace requests to cache. Select this option to display trace data for requests until Number of trace requests to cache is reached.
When you are finished troubleshooting the Web site, disable debugging and tracing to get maximum performance from your Web application. When tracing is enabled for a page, trace information might appear on any browser that makes a request for the page from the server. Because tracing displays sensitive information, such as the values of server variables, it can represent a security threat. Make sure that you disable page tracing for the page before publishing the Web application to a production server.
To configure a custom error page for the Web site, click Define default error page and then specify the following:. The Application tab provides a simple Web interface for managing configuration settings that are stored in the Web. This is a predefined configuration section provided by the. NET Framework. The highlighted lines in the following code are an example configuration file that is generated after you use the Web Site Administration Tool to create an application setting named ApplicationName.
The highlighted lines in the following code are generated after you use the Web Site Administration Tool to take an application offline.
0コメント