Solved

How to display custom disclaimer tag from web.config on asp.net page?

Posted on 2007-04-05
3
1,038 Views
Last Modified: 2012-06-21
I have an ASP .Net form and I want to display a disclaimer info on it from the web.config. The disclaimer can be different and customized for each customer. I want to add a custom tag in web.config like shown below..

<disclaimer>
This software....
line2 of disclaimer..
line3..
can be any number of lines..
</disclaimer>

I investigated the custom configuarion features of asp .net 2.0, but it does not allow multiline data (variable length)  like this..It needs scalar values like these..

<ScottsSettings
     quoteOfTheDay="Hello, World!"
     yourAge="28">
   <favoriteStates>
      <add name="California" abbreviation="CA" />
      <add name="Missouri" abbreviation="MO" />
      <add name="Illinois" />
   </favoriteStates>
</ScottsSettings>

Any ideas on how i could implement this?

Thanks, LM
0
Comment
Question by:LubomirMasar
  • 2
3 Comments
 
LVL 35

Accepted Solution

by:
mrichmon earned 250 total points
ID: 18860219
You could write your own xml file like this

disclaimer.xml
<?xml version="1.0" encoding="utf-8" ?>
<disclaimer>
<![CDATA[
This software....
line2 of disclaimer..
line3..
can be any number of lines..
]]>
</disclaimer>

Note the CDATA should be used if you want multiple lines and/or formatting

Then access like this:
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load("path to your xml file");
string disclaimer = xmlDoc.DocumentElement["disclaimer"].InnerText;
0
 

Author Comment

by:LubomirMasar
ID: 18860507
mrichmon,
In that approach, why deal with XML at all? I could write a simple text file having disclaimer content and then use System.IO streamreader class to read and display on page correct? I had tested this and it works easily. But the customer prefers not to use a separate file, likes to use web.config for all their custom configuration.

I can also do like this

<appSettings>
<add key="DISCLAIMER_LINE1" value="Disclaimer first line"
<add key="DISCLAIMER_LINE2" value="Disclaimer second line"
<add key="DISCLAIMER_LINE3" value="Disclaimer third line"
</appSettings>
 and process like this

string disclaimer = ConfigurationSettings.AppSettings["DISCLAIMER_LINE1"].ToString();
disclaimer = disclaimer + ConfigurationSettings.AppSettings["DISCLAIMER_LINE2"].ToString();

But this is a bit ugly too. We have to decide a max number of lines for disclaimer ahead of time.

Thanks for the response..I think there must be a better way..


0
 
LVL 35

Expert Comment

by:mrichmon
ID: 18861164
>>In that approach, why deal with XML at all? I could write a simple text file having disclaimer content and then use System.IO streamreader class to read and display on page correct

You could.  But what I showed the only difference between that and the web.config is that ConfigurationManager does the xmldocument load lines for you... You could even call it disclaimer.config if you wanted....
0

Featured Post

The New “Normal” in Modern Enterprise Operations

DevOps for the modern enterprise offers many benefits — increased agility, productivity, and more, but digital transformation isn’t easy, especially if you’re not addressing the right issues. Register for the webinar to dive into the “new normal” for enterprise modern ops.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
RegEx with optional part 4 42
LINQ Select all records by MAX data syntax help 1 17
jquery + C#.net radiobuttonlist 3 30
Upgrade code from VS 2010 to VS 2015 7 15
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

856 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question