自定义配置文件 asp.net

发布于 2024-10-01 01:24:38 字数 2200 浏览 4 评论 0原文

我正在尝试根据这篇文章使用 VB.NET 在 ASP.NET 中使用自定义配置文件: 如何分配配置文件值?

我在文件夹 /class/Usuario 下创建了我的配置文件类.vb 使用 Locus 命名空间。该类继承了上面帖子中指定的 ProfileBase。

问题是,当我尝试在 web.config 上引用该类时,它会给出以下错误消息:

Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately. 
Compiler Error Message: CS0246: The type or namespace name 'Locus' could not be found (are you missing a using directive or an assembly reference?)

这就是我声明 web.config 的方式:

  <profile defaultProvider="CustomizedProfileProvider" inherits="Locus.Usuario">
    <providers>
      <clear />
        <add name="CustomizedProfileProvider"
             type="System.Web.Profile.SqlProfileProvider"
             connectionStringName="BDSIT" />          
    </providers>
  </profile>   

“继承”部分失败了

我尝试使用谷歌搜索,但是我无法让它工作

关于我做错了什么有任何线索吗?

提前致谢!

编辑:这是该类的代码:

Namespace Locus
Public Class Usuario
    Inherits ProfileBase

    Public ReadOnly Property UsuarioActual() As Usuario
        Get
            Return ProfileBase.Create(Membership.GetUser.UserName)
        End Get
    End Property

    Public Property nombre() As String
        Get
            Return Me.GetPropertyValue("nombre")
        End Get
        Set(ByVal value As String)
            Me.SetPropertyValue("nombre", value)
            Save()
        End Set
    End Property

    Public Property apellido() As String
        Get
            Return Me.GetPropertyValue("apellido")
        End Get
        Set(ByVal value As String)
            Me.SetPropertyValue("apellido", value)
            Save()
        End Set
    End Property

    Public Property pin() As String
        Get
            Return Me.GetPropertyValue("pin")
        End Get
        Set(ByVal value As String)
            Me.SetPropertyValue("pin", value)
            Save()
        End Set
    End Property

End Class

End Namespace

I'm trying to use a custom profile in ASP.NET using VB.NET according to this post:
How to assign Profile values?

I created my profile class under the folder /class/Usuario.vb using the Locus namespace. The class inherits ProfileBase as specified in the post above.

The problem is that when I try to make a reference to that class on my web.config it gives me this error message:

Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately. 
Compiler Error Message: CS0246: The type or namespace name 'Locus' could not be found (are you missing a using directive or an assembly reference?)

This is how I'm declaring my web.config:

  <profile defaultProvider="CustomizedProfileProvider" inherits="Locus.Usuario">
    <providers>
      <clear />
        <add name="CustomizedProfileProvider"
             type="System.Web.Profile.SqlProfileProvider"
             connectionStringName="BDSIT" />          
    </providers>
  </profile>   

The "inherits" part is what's failing

I tried googling but I couldn't get it working

Any clues on what am I doing wrong?

Thanks in advance!

EDIT: This is the code of the class:

Namespace Locus
Public Class Usuario
    Inherits ProfileBase

    Public ReadOnly Property UsuarioActual() As Usuario
        Get
            Return ProfileBase.Create(Membership.GetUser.UserName)
        End Get
    End Property

    Public Property nombre() As String
        Get
            Return Me.GetPropertyValue("nombre")
        End Get
        Set(ByVal value As String)
            Me.SetPropertyValue("nombre", value)
            Save()
        End Set
    End Property

    Public Property apellido() As String
        Get
            Return Me.GetPropertyValue("apellido")
        End Get
        Set(ByVal value As String)
            Me.SetPropertyValue("apellido", value)
            Save()
        End Set
    End Property

    Public Property pin() As String
        Get
            Return Me.GetPropertyValue("pin")
        End Get
        Set(ByVal value As String)
            Me.SetPropertyValue("pin", value)
            Save()
        End Set
    End Property

End Class

End Namespace

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

少年亿悲伤 2024-10-08 01:24:38

我在命名空间之前添加了项目名称,这解决了问题,如下所示:

<profile defaultProvider="CustomizedProfileProvider" inherits="ProjectName.Locus.Usuario">

我现在正在测试配置文件,但目前 IIS 不会抛出错误并且编译成功。

谢谢,我希望这对某人有帮助

I added the project name before the Namespace and that fixed the issue, somethint like this:

<profile defaultProvider="CustomizedProfileProvider" inherits="ProjectName.Locus.Usuario">

I'm now testing the profile but for now the IIS is not throwing the error and the compilation succeeds.

Thanks, I hope this helps someone

云巢 2024-10-08 01:24:38

您是否在 web.config 中添加了对自定义命名空间的引用?

<namespaces>
<add namespace="Locus" />
</namespace>

Have you added a reference to your custom namespace in web.config?

<namespaces>
<add namespace="Locus" />
</namespace>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文