I have been trying to find ways around this code or to do something about it but I still don't understand a few things about creating websites in ASP.NET. So my problem is the following:
return int.Parse(Properties.Settings.Default["SiteId"].ToString());
and
Main
Properties.Settings.Default["SiteId"] = value;
Any help translating from Win to Web will be really helpful.
theLizardPosted Jan 14, 2010, 4:57 PM
This is pretty basic
return int.Parse(Properties.Settings.Default["SiteId"].ToString()); //get the value
Properties.Settings.Default["SiteId"] = value; //set the value
you could have a text file that stores the values and have a function called
public string getMyValue(string what)
{
//you would of course need code to read through the text file or get a database record
return(my value);
}
and
public void setMyValue(string what, string value)
{
//again, you would of course need code to read through the text file
write your code
}
if you are using code behind in your web site, having this type of code in an generic class ie, one that is not specific or have Web references of windows forms references just system type references, then the code would work in both web and forms applications.
The following code example is good for both...
In both Web apps and Form apps you simply need to give the using directive
using generic;
to use this on your forms web or otherwise, whenever you need to access its methods
generic.web_forms wb = new web_forms();
now you have a .cs that is easy to maintain for both platforms.
using System;
using System.Collections.Generic;
using System.Text;
namespace generic
{
public class web_forms
{
public string getMyValue(string what)
{
//you would of course need code to read through the text file
return("");
}
public void setMyValue(string what, string value)
{
//again, you would of course need code to read through the text file
//write your code
}
}
}
I hope I have understood your problem, if not let me know...
regorPosted Jan 14, 2010, 9:16 AM
Is there not other way that is not through the web.config, I mean in the long turn I dont want it to be such a global part of the website as I am running this code under a class.
Thanks.
Saroj SahooPosted Jan 14, 2010, 5:53 AM