views:

54

answers:

1

In the Security model for out ASP.Net website (.Net 3.5) we store the page name:

page.GetType().Name

as the primary key in a database table to be able to lookup if a user has access to a certain page. The first time a page is visited this record is created automatically in the database.

We have exported these database statements to insert scripts, but each time a new page gets created we have to update the scripts, not a huge issue, but I would like to find an automated way to do this.

I created an attribute that I tagged a few pages with and then wrote a small process to get all the objects that have this attribute, through the reflection create an instance and insert the record using the same code to for page records mentioned above:

IEnumerable<Type> viewsecurityPages = Assembly.GetExecutingAssembly().GetTypes().Where(t => t.IsDefined(typeof(ViewSecurityAttribute),false));

            foreach (Type t in viewsecurityPages)
            {
                object obj = Activator.CreateInstance(t, false);

           //clip..(This code just checks if the record already exists in the DB)

                if (feature == null)
                {

                    Attribute attb = Attribute.GetCustomAttribute(t, typeof(ViewSecurityAttribute));

                    if (attb != null)
                    {
                        CreateSecurableFeatureForPage((Page)obj, uow, attb.ToString());
                    }

                }

            }

The issue is that page.GetType().Name when the page goes through the actual page cycle process is something like this:

search_accounts_aspx

but when I used the activator method above it returns:

Accounts

So the records don't match the in the security table. Is there anyway to programtically "visit" a webpage so that it goes through the actual page lifecycle and I would get back the correct value from the Name parameter?

Any help/reference will be greatly appreciated.

A: 

Interesting problem...

Of course there's a (too obvious?) way to programmatically visit the page... use System.Net.HttpWebRequest. Of course, that requires the URI and not just a handle to the object. This is a "how do we get there from here?" problem.

My suggestions would be to simply create another attribute (or use that same one) which stores the identifier you need. Then it will be the same either way you access it, right?

Alternatively... why not just use a 3rd party web spider/crawler to crawl your site and hit all the pages? There are several free options. Or am I missing something?

Bryan
I forgot to mention that I tried a spider. The site is really a business app (sold to run on internal intranets) so a lot of the "links" actually happen through submit buttons, etc. I could work on a sitemap I guess...I hadn't thought of changing the attribute to be the URI and using an HTTP Request to visit those. This would work but would still require some manual effort when the site changes, interesting thought, I have to think about it.
mlowrance