开发者

ASP.NET applicationSettings (Giving Me) Fits

开发者 https://www.devze.com 2023-01-17 18:01 出处:网络
I\'ve read all of the examples and I\'ve yet to figure out how to get information out of the web.config file using applicationSettings (as opposed to appSettings). I have the following for my configSe

I've read all of the examples and I've yet to figure out how to get information out of the web.config file using applicationSettings (as opposed to appSettings). I have the following for my configSections:

<configSections>
    <sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
        <section name="ExcelREST.FDAllU开发者_Python百科pAvailabilityTable.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false"/>
    </sectionGroup>
</configSections>

Then, for applicationSettings I have:

<applicationSettings>
    <ExcelREST.FDAllUpAvailabilityTable.Settings>
        <setting name="RESTPageURI" serializeAs="String">
            <value>http://team/_vti_bin/ExcelRest.aspx</value>
        </setting>
        <setting name="WorkbookLocation" serializeAs="String">
            <value>/sites/tel/Shared Documents/FD Dashboard Reports.xlsx</value>
        </setting>
        <setting name="ResourceLoction" serializeAs="String">
            <value>/model/Tables('FDAllUpAvailabilityTable')?$format=html&amp;Ranges('MonthParameter')={0}</value>
        </setting>
    </ExcelREST.FDAllUpAvailabilityTable.Settings>
</applicationSettings>

Now, I suspect that I may be making an assumption that's not valid; namely, that the appropriate classes will be generated to access my configuration information by Visual Studio (2010). I've simplified the example in that I really want to have several <section name="..." > within configSections.

What (probably obvious) step am I missing here? (I'm coding in C# and this is an ASP.NET 4.0 MVC application.) I'm about ready to bag it and just go with the simplistic appSettings.

Thanks!


If you go to the Project / Properties / Settings tab and click on the blue link, you'll get a new Settings.settings file generated in the Properties folder for the project.

That file generates a Settings.cs file that contains strongly typed properties for the settings you define in the editor, and gets its values from an applicationSettings configuration section that you can include in any managed process's .config file.


I think you really want to make a custom configuration section not a custom application settings element.


If you have done the above correctly, you can just access your data via

string restPageUri = ExcelREST.FDAllUpAvailabilityTable.Settings.Default.RESTPageURI;

string workbookLocation= ExcelREST.FDAllUpAvailabilityTable.Settings.Default.WorkbookLocation;

However, it looks like you have created these entries by typing them directly into your web.config. If you do not have a ExcelREST.FDAllUpAvailabilityTable.Settings class in your project, then you have to create one. The best way to create one is to use the Visual Studio settings wizard.

0

精彩评论

暂无评论...
验证码 换一张
取 消