473,473 Members | 2,141 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Reading from web.config

8 New Member
Is it correct to read from web.config file in the following way? i am using asp.net 2.0 VS 2005.I get the following error

Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace:


[NullReferenceException: Object reference not set to an instance of an object.]
anmar.SharpWebMail.UI.Login.Login_Click(Object sender, EventArgs args) in login.cs:75
System.EventHandler.Invoke(Object sender, EventArgs e) +0
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +105
System.Web.UI.WebControls.Button.RaisePostBackEven t(String eventArgument) +107
System.Web.UI.WebControls.Button.System.Web.UI.IPo stBackEventHandler.RaisePostBackEvent(String eventArgument) +7
System.Web.UI.Page.RaisePostBackEvent(IPostBackEve ntHandler sourceControl, String eventArgument) +11
System.Web.UI.Page.RaisePostBackEvent(NameValueCol lection postData) +33
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +5102


The point where the error is shown is

int login_mode = (int)Application["sharpwebmail/login/mode"];

Are application variables available in asp.net 2.0
Jul 31 '07 #1
2 1573
Plater
7,872 Recognized Expert Expert
Values stored in web.config are generally accessed like this:

Code:
Expand|Select|Wrap|Line Numbers
  1. private static AppSettingsReader ap = new AppSettingsReader();
  2. public static int SitesPerGrouping
  3.     {
  4.         get
  5.         {
  6.             return (int)ap.GetValue("SitesPerGrouping", typeof(int));
  7.         }
  8.     }
  9.  
web.config
Expand|Select|Wrap|Line Numbers
  1. <configuration>
  2.     <appSettings>
  3.         <add key="SitesPerGrouping" value="500"/>
  4.     </appSettings>
  5. </configuration>
  6.  
Jul 31 '07 #2
arun1985
8 New Member
Values stored in web.config are generally accessed like this:

Code:
Expand|Select|Wrap|Line Numbers
  1. private static AppSettingsReader ap = new AppSettingsReader();
  2. public static int SitesPerGrouping
  3.     {
  4.         get
  5.         {
  6.             return (int)ap.GetValue("SitesPerGrouping", typeof(int));
  7.         }
  8.     }
  9.  
web.config
Expand|Select|Wrap|Line Numbers
  1. <configuration>
  2.     <appSettings>
  3.         <add key="SitesPerGrouping" value="500"/>
  4.     </appSettings>
  5. </configuration>
  6.  
<?xml version="1.0" encoding="UTF-8" ?>

<configuration>
<configSections>
<section name="log4net" type="System.Configuration.IgnoreSectionHandler" />
<section name="sharpwebmail" type="anmar.SharpWebMail.SharpWebMailConfigHandler , SharpWebMail" />
</configSections>
<sharpwebmail>
<!--
The <general> section is used to configure global options
default_lang: Default localization language
title: Title displayed in every page.
-->
<general
default_lang="en"
title = "[general title] configuration setting"
/>
<!--
The <login> section is used to configure login screen options

title: Title displayed in login screen

mode:
1-> Full email required for login
2-> Any username is allowed
3-> Any username is allowed but the append
string is added to supplied username

append: text to append to user supplied username

serverselection:
auto -> The server is selected using the configured regular expressions.
manual -> The server is selected by the user.

enablequerystringlogin: Login credentials can be given in the querystring of
the login page. The provided credentials must comply with the same
restrictions as when provided manually. The querystring items used are
username and password. Possible values:
true-> enabled
false-> disabled

Note: Be careful when using this option as the passwords will be seen in
clear text easily (for example in the browser history).
Example: http://localhost/login.aspx?username=anmar@dev.anmar.eu.org&passwor d=testpass
-->
<login
title="[login title] configuration setting"
mode="1"
append=""
serverselection="auto"
enablequerystringlogin="false"
/>

If i have a web.config section like this and i have to read the value of mode in login section then how to read the value?
Aug 1 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Sami | last post by:
Hello, I have this problem that I need your help with : I am reading a config file that contain the following : 2004 update
3
by: spacekid | last post by:
Hi there I am exposing a c# assembly as a COM component (regasm /codebase) and calling it from classic asp. When I try to call the ConfigurationSettings.AppSettings function in the c# assembly,...
2
by: news.microsoft.com | last post by:
Hi After conducting a several searches, I wasn't sure where to post this question. So my apologiesbefore hand for double posting this and possibly posting to the wrong forum(s). Okay, I have...
1
by: comic_rage | last post by:
Hi, I am trying to read from my application config file and keep getting null. Here is my config file My application is called SampleApp.exe
10
by: Ryan | last post by:
I've created a custom configuration section that inherits (naturally) from System.Configuration.ConfigurationSection. The configuration section is working 99% fine, however I keep coming across a...
2
by: marek zegarek | last post by:
Hello! On my server I have Sharepoint portal server as default web site I create there a web application folder with form.aspx file. When I'm trying to run aspx, i get an error. Page is trying...
5
by: alf | last post by:
Hi folks, I'm trying to read a web.config section using RoleManagerSection settings = (RoleManagerSection)System.Configuration.ConfigurationManager.GetSection("system.web/roleManager"); and I...
9
by: Milsnips | last post by:
Hi all. i'm tryng to implement the Rewrite.NET url rewritining functionality into a test project i've created, however i am hitting a problem at this line (direct from the web example): ...
1
by: M Irfan | last post by:
Hello all, Recently I have started working in .NET 2.0. I am developing a web service application that references a DLL component written in C# 2.0. The component has its own config file which...
1
by: vijayarl | last post by:
Hi Everyone, i have the written this logic : basically a file operation open (CONFIGFILE, "$config_file") or die; while (<CONFIGFILE>) { chomp;
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.