Programicatlly访问(全部)ASP.Net页面的网站(S)?页面、全部、网站、Programicatlly

2023-09-07 10:40:58 作者:┈涵暖?筱暖┆

在安全模式了ASP.Net网站(.NET 3.5)我们保存网页名称:

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

page.GetType()。名称

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.

我创建了我标记的几页用,然后写了一个小程序,以获取具有此属性通过反射创建一个实例,并使用相同的code为页面插入记录的所有对象,属性记录上面提到的:

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());
                    }

                }

            }

问题是,当页面经过实际的页面循环过程page.GetType()名称是这样的:

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:

帐户

所以,记录不匹配的安全表。反正是有programtically参观的网页,以便它经过实际的页面生命周期,我会回来的名称参数的正确值?

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?

任何帮助/引用将大大AP preciated。

Any help/reference will be greatly appreciated.

推荐答案

有趣的问题...

当然,还有一个(太明显了?)以编程方式访问网页...使用System.Net.HttpWebRequest。当然,这需要的URI,而不只是一个句柄对象。这是我们如何从这里到达那里?问题。

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?