【发布时间】:2014-01-28 20:50:18
【问题描述】:
我正在使用 ASP.net 和 C#,试图从 web.config 文件访问另一个用户的 Profile 属性。
我要访问的属性具有我创建的类的自定义类型ClassesList:
public class ClassesList
{
public struct Class_
{
public string name;
public string teacherName;
public string startDate, endDate;
public int numOfEnrolledStudents;
public int maxNumOfStudents;
public string[] studentsNames;
public string accessKey;
public bool IsActive;
}
public Class_[] Classes;
public ClassesList()
{
this.Classes = new Class_[200];
for (int i = 0; i < 200; i++)
{
Classes[i].IsActive = false;
Classes[i].studentsNames = new string[500];
}
}
}
这是我在 web.config 文件中的个人资料:
<profile>
<properties>
<add name="ClassList" type="ClassesList" allowAnonymous="false" />
</properties>
</profile>
我正在使用此语句获取另一个用户的个人资料(在 for 循环中)
ProfileBase currentTeacherProfile = ProfileBase.Create(teacherList[i], true);
所以现在我有了个人资料,我只需要访问我想要的个人资料属性,那就是accessKey
我正在尝试使用此代码来获取属性,但我得到了未找到的异常
currentTeacherProfile.GetPropertyValue("ClassList.Classes[0].accessKey")
注意:使用
访问当前用户的配置文件属性Profile.ClassList.Classes[0].accessKey
有效,但在其他用户的情况下无效。
谢谢。
【问题讨论】: