简体   繁体   English

如何从项目类访问ASP默认属性?

[英]How can I access ASP default properties from project classes?

I have a class that tries to access the options of the web app, but fails to compile during Run or Debug. 我有一个试图访问Web应用程序选项的类,但是在运行或调试期间无法编译。

CS0122: 'IBBFCP.Properties.Settings' no es accesible debido un su Nivel de Protección (It is not accessible due to its protection level) CS0122:“ IBBFCP.Properties.Settings”没有可访问的保护措施(由于其保护级别,因此无法访问)

The code is very simple and will only publish important parts: 该代码非常简单,只会发布重要的部分:

public class HelperFideicomiso : IDisposable
{
    private String Url
    {
        get
        {
           return global::IBBFCP.Properties.Settings.Default.WSLA_FideicomisoEndpointURL;
        }
    }
}

The project compile but fail running. 项目已编译,但无法运行。

The property is well constructed by the Visual Studio 2005 IDE and value stored in Web.config 该属性由Visual Studio 2005 IDE很好地构造,并且值存储在Web.config

The class is internal to the project, there is no reference or DLL involved. 该类在项目内部,不涉及引用或DLL。

Thanks. 谢谢。

Update: 08/14 更新时间:08/14

Simplifying the stage. 简化舞台。 After creating a web application, define a property and reference it from a page and a class get the same error: 创建Web应用程序后,定义一个属性并从页面中引用它,而一个类将得到相同的错误:

CodeBehind: 代码背后:

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        this.Label1.Text = WebApplication1.Properties.Settings.Default.Setting;
        this.Label2.Text = new Configuracion().Setting;
    }
}

Referenced class. 引用的类。 This class fail : 此类失败

internal class Configuracion
{
    public string Setting = WebApplication1.Properties.Settings.Default.Setting;
}

In your project, expand Properties and double click on the Settings.settings file. 在项目中,展开“属性”,然后双击“ Settings.settings”文件。 This will open it. 这将打开它。 Look at the top in the toolbar, and change the Access Modifier to Public. 查看工具栏的顶部,然后将“访问修饰符”更改为“公共”。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM