【问题标题】:How to use Profile in ASP.NET?如何在 ASP.NET 中使用配置文件?
【发布时间】:2011-02-22 17:09:14
【问题描述】:

我尝试学习 asp.net 配置文件管理。但我在 xml firstName、LastName 和其他下面添加了。但我不能写个人资料。如果我尝试编写 Profile 属性。卓我的编辑器配置文件:错误 1 ​​当前上下文中不存在名称“配置文件”C:\Documents and Settings\ykaratoprak\Desktop\Security\WebApp_profile\WebApp_profile\Default.aspx.cs 18 13 WebApp_profile 我该怎么做?


    <authentication mode="Windows"/>
    <profile>
      <properties>
        <add name="FirstName"/>
        <add name="LastName"/>
        <add name="Age"/>
        <add name="City"/>
      </properties>
    </profile>


 protected void Button1_Click(object sender, System.EventArgs e)
        {
            Profile.FirstName = TextBox1.Text;
            Profile.LastName = TextBox2.Text;
            Profile.Age = TextBox3.Text;
            Profile.City = TextBox4.Text;

            Label1.Text = "Profile stored successfully!<br />" +
                "<br />First Name: " + Profile.FirstName +
                "<br />Last Name: " + Profile.LastName +
                "<br />Age: " + Profile.Age +
                "<br />City: " + Profile.City;
        }

【问题讨论】:

  • 如果你这样做Context.Profile怎么办?
  • 好的,但是姓氏和其他人在哪里:(
  • 您是否授予他们匿名访问权限?例如&lt;add name="FirstName" allowAnonymous="true" /&gt; 在 web.config 中?

标签: c# .net asp.net profile


【解决方案1】:

要以您描述的方式使用配置文件需要一个网站项目。您的问题意味着您有一个 Web 应用程序项目。

在 Web 应用程序项目中使用配置文件比使用网站需要更多的工作,因为不会为您生成动态 ProfileCommon 类。

这里有一些参考资料可帮助您了解差异。

http://weblogs.asp.net/anasghanem/archive/2008/04/12/the-differences-in-profile-between-web-application-projects-wap-and-website.aspx

还有一个工具可以让您在 Web 应用程序中更轻松地使用配置文件。

http://weblogs.asp.net/joewrobel/archive/2008/02/03/web-profile-builder-for-web-application-projects.aspx

【讨论】:

    【解决方案2】:

    问题是Profile已经存在于web.config中。所以你必须将你的属性添加到配置文件中,删除 using System.Web.Profile 并再次写入(Using System.Web.Profile;)。

    【讨论】:

      【解决方案3】:

      此 URL 描述了如何解决 Web 应用程序中的配置文件问题:Using ASP.Net Profile Feature in a Web Application Project

      【讨论】:

        【解决方案4】:

        在您的页面中添加此命名空间System.Web.Profile

        using System.Web.Profile;
        

        【讨论】:

        • 使用 System.Web.Profile;我用它。但结果是一样的。我在我的代码上添加了一张图片。看上面。请帮帮我:)
        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2011-02-19
        • 2011-03-02
        • 1970-01-01
        • 2011-09-02
        • 2016-09-01
        • 2013-09-20
        • 2011-12-19
        相关资源
        最近更新 更多