|
 |
aspdotnet_website_programming thread: Don't understand context.Cache["Accounts_Settings"];
Message #1 by "Rod Maupin" <gridman144@m...> on Thu, 19 Sep 2002 15:18:06
|
|
I have incorporated the Accounts and Core modules into my own project,
but I have having a problem when the data variable is created below (in
ModuleConfig.cs). I understand about having the appropriate
[app_settings] section in web.config, and then also a config folder with
the proper config files that contain the configuration strings. I have
all that. However, everytime my code executes, data (in the code below)
always turns out to be NULL. When stepping through thePhile app, I have
noticed that data is never NULL. My question is, I don't understand
where "Accounts_Settings" is being retrieved from.
Thanks,
Rod
ModuleConfig.cs
---------------
public class ModuleConfig
{
public static ModuleSettings GetSettings()
{
HttpContext context = HttpContext.Current;
ModuleSettings data=(ModuleSettings)context.Cache["Accounts_Settings"];
if (data == null)
{
Message #2 by "Charles Walsek" <cwalsek@w...> on Sat, 21 Sep 2002 07:52:06 -0400
|
|
Hi Rod,
I've been doing the same thing, building the app from scratch using VS.NET.
I got through building the Accounts project (chapter 5), but hit a few pot
holes along the way. I thought the book and sometimes the download code
contained some omissions, so I added some code snippets along the way to
make my project work. Dealing with the problems has helped me gain a better
understanding; it's really a great book.
I did not encounter your situation, but I know the variable will be NULL if
it can't pull the connection string from cache. The first time thru, it
should be NULL. It will build the connection string and place it into cache
for retreival the next time. There might be a setting somewhere that
specifies how long cache is to be kept. Hope this helps; it's the best I
can offer.
>However, everytime my code executes, data (in the code below)
> always turns out to be NULL. When stepping through thePhile app, I have
> noticed that data is never NULL. My question is, I don't understand
> where "Accounts_Settings" is being retrieved from.
>
> Thanks,
>
> Rod
> ModuleConfig.cs
> ---------------
>
> public class ModuleConfig
> {
> public static ModuleSettings GetSettings()
> {
> HttpContext context = HttpContext.Current;
>
> ModuleSettings data=(ModuleSettings)context.Cache["Accounts_Settings"];
>
> if (data == null)
> {
> ---
Message #3 by "Rod Maupin" <gridman144@m...> on Sat, 21 Sep 2002 15:45:46
|
|
You're correct. The first time through, it does place the connection
string in the cache and to make it subsequently available. What puzzled
me was that in the beginning of that routine, it looks
for "Accounts_Settings", which I have not found anywhere. Because the
way the code is set up, the section in the Web.config file reads as
follows:
<appSettings>
<add key="Accounts_SettingsFile" value="Config/Accounts.Config" />
</appSettings>
So, I couldn't understand where you would ever find a key
called "Accounts_Settings".
The book is great. I'm only using the sections on the core and accounts
class libraries, and some code out of the users module. I don't need
news, forums, polls, or the like. Even so, it's a great book to have.
It took me a while to understand what was going on in the book. Still on
a learning curve with ASP.NET.
If you're interested in security, Wrox came out with a new book last
month called "ASP.NET Security". It's really good. Seems like you would
need to know it for ASP.NET development.
Rod
Message #4 by "Charles Walsek" <cwalsek@w...> on Sat, 21 Sep 2002 13:39:41 -0400
|
|
I think I know what you are looking for. The way I understand it is that
web.config contains the key "Accounts_SettingsFile", which points to the
accounts.config file.
The accounts.config file contains the connection string. And when it's
retreived the first time, it's placed in cache using the variable
"Accounts_Settings". This variable is made available through the context
object. You should not find any reference to this variable, other than the
ModuleConfig class.
I can relate to the learning curve. I'm approaching it from a VC++ / MFC
background, but I still feel like a newbie. What did you get from the new
Security book? I eat this stuff for breakfast.
--Chas
>
> So, I couldn't understand where you would ever find a key
> called "Accounts_Settings".
>
>
> It took me a while to understand what was going on in the book. Still on
> a learning curve with ASP.NET.
>
> If you're interested in security, Wrox came out with a new book last
> month called "ASP.NET Security". It's really good. Seems like you would
> need to know it for ASP.NET development.
>
> Rod
> ---
Message #5 by "Rod Maupin" <gridman144@m...> on Tue, 24 Sep 2002 23:06:22
|
|
Thanks for the reply Charles. You answered my question.
I also am coming from an MFC/VC++ background, so I am having the same
learning curve.
The ASP.NET Security book is from Wrox also. It has a lot of great stuff
in there about what hackers try and do to get into systems. It's
interesting to me, because I didn't know any of that stuff.
I was dissappointed in one of their code examples. The guy is using a
SQL Server db to store login credentials, yet he uses OleDbConnection
instead of SqlConnection. Can't understand why he wouldn't use the
optimized version.
I haven't read the whole book yet, as I'm bouncing between several books,
but it seems worth the money.
Thanks again for the help.
Rod
|
|
 |