ASP.NET - Is it possible to obtain a list/collection of all pages a user is authorized to view?
I'm using forms authentication in my C# based web site, with the authentication defined in web.config files in the various folders/sub-folders. I want to write a generic administration menu system, that lists all of the admin pages that the use is authorized to open. As I add pages, I want them开发者_Go百科 to automatically show up in the menu. So...
I need to obtain a list/collection of all pages that the active user is authorized to open. Is this possible in ASP.Net 3.5?
I assume that ASP.Net has an internal collection of pages somewhere, together with their required roles (as it must check somewhere when you attempt to open a page)?
I would suggest looking into using a sitemap (in ASP.Net, web.SiteMap). Then you can use the SiteMap as a datasource (as well as define roles, etc for each page).
You assume incorrectly... There is no internal listing of these pages, only the file system. Access is checked on a file-by-file basis when ASP.NET attempts to open the page.
To do what you're looking for, you'll have to code it up yourself using System.IO and getting the authorization settings from web.config.
精彩评论