473,804 Members | 2,024 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

how to read web.config from iis web directory

9 New Member
hi all
i am using a windows application as well as web application developed in visual studio 2010 beta 2 using .net framework 4 on windows xp/windows server 2008/windows7
i am able to read web.config file on system running windows XP sp2 but same is not read by windows 7 and windows server 2008
i installed my web application on iis 7 on said windows with .net 4 but it not read web.config by my windows application.
i used below code on form_load in windows application for reading that web.config-
Expand|Select|Wrap|Line Numbers
  1. Dim webStr As Configuration.Configuration=WebConfigurationManager.OpenWebConfiguration("/Site/")
  2. Dim webConstr As String = webStr.ConnectionStrings.ConnectionStrings("connStr").ConnectionString
  3.                 Dim getIdx As Integer = webConstr.IndexOf("User ID=", 0)
  4.                 getIdx += 8
  5.                 Dim getIdx2 As Integer = webConstr.IndexOf(";", getIdx)
  6.                 Dim strLen As Integer = getIdx2 - getIdx
  7.                 sqlUid = webConstr.Substring(getIdx, strLen)
  8.  
below is my web.config exist in c:\inetpub\wwwr oot\site\ folder -
Expand|Select|Wrap|Line Numbers
  1. <?xml version="1.0"?>
  2. <configuration>
  3.     <connectionStrings>
  4.         <remove name="LocalSqlServer"/>
  5.         <add name="LocalSqlServer" connectionString="Data Source=myMacine;Initial Catalog=ASPNETDB;Persist Security Info=True;integrated security=true" providerName="System.Data.SqlClient"/>
  6.         <add name="connStr" connectionString="Data Source=myMachine;Initial Catalog=abc;Persist Security Info=True;User ID=xyz;" providerName="System.Data.SqlClient"/>
  7.     </connectionStrings>
  8. .......
  9. ......
  10. </configuration>
  11.  
the error comes in reading this is -
Expand|Select|Wrap|Line Numbers
  1. Failed to map the path '/site'
and below is the full exception path-

Expand|Select|Wrap|Line Numbers
  1. at System.Web.Configuration.ProcessHostConfigUtils.MapPathActual(String siteName, VirtualPath path)
  2.    at System.Web.Configuration.ProcessHostMapPath.MapPathCaching(String siteID, VirtualPath path)
  3.    at System.Web.Configuration.ProcessHostMapPath.System.Web.Configuration.IConfigMapPath2.MapPath(String siteID, VirtualPath path)
  4.    at System.Web.Configuration.WebConfigurationHost.InitForConfiguration(String& locationSubPath, String& configPath, String& locationConfigPath, IInternalConfigRoot configRoot, Object[] hostInitConfigurationParams)
  5.    at System.Configuration.Configuration..ctor(String locationSubPath, Type typeConfigHost, Object[] hostInitConfigurationParams)
  6.    at System.Configuration.Internal.InternalConfigConfigurationFactory.System.Configuration.Internal.IInternalConfigConfigurationFactory.Create(Type typeConfigHost, Object[] hostInitConfigurationParams)
  7.    at System.Web.Configuration.WebConfigurationHost.OpenConfiguration(WebLevel webLevel, ConfigurationFileMap fileMap, VirtualPath path, String site, String locationSubPath, String server, String userName, String password, IntPtr tokenHandle)
  8.    at System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration(String path)
  9.    at appName.FormName.Form_Load(Object sender, EventArgs e) in E:\myapp\page.vb:line 130
I hope anyone has the answer for me
i have to install it by two day so please help me
thanks in advanced
Jan 15 '10 #1
5 9122
Frinavale
9,735 Recognized Expert Moderator Expert
Instead of "opening" the web.config have you considered just using:

Expand|Select|Wrap|Line Numbers
  1. Dim webConstr As String = System.Configuration.ConfigurationManager.ConnectionStrings("connStr").ConnectionString
-Frinny
Jan 15 '10 #2
gr8Ashish
9 New Member
thanks for your reply frinny
but it does not help and its almost same as i already did above..
well i am not able to read connection string by above methods till now

you or anybody has the solution pls tell me
Jan 18 '10 #3
Frinavale
9,735 Recognized Expert Moderator Expert
Did you try what I recommended?
It may look "close" to what you're doing, but it's not the same thing.
If you did try this, then you should have got a different error message....

I used MSDN to look up what the OpenWebConfigur ation Method did and the documentation said that it opens the web-application configuration file as a Configuration object using the specified virtual path to allow read or write operations.

I'm going to pretend that you just don't want to try what I recommended previously and will recommend that you try using this instead:
Expand|Select|Wrap|Line Numbers
  1. Dim webStr As Configuration.Configuration=WebConfigurationManager.OpenWebConfiguration("~/")
Or, if your web.config file is located in the root directory of the site, don't even pass it "~/" just pass it nothing because the documentation says that if a null reference (Nothing in Visual Basic) is passed to the OpenWebConfigur ation method the root web.config file is opened....

So you could try:
Expand|Select|Wrap|Line Numbers
  1. Dim webStr As Configuration.Configuration=WebConfigurationManager.OpenWebConfiguration()
And it should open the root web.config file.

-Frinny
Jan 18 '10 #4
gr8Ashish
9 New Member
Frinny
this method-
Expand|Select|Wrap|Line Numbers
  1. Dim webStr As Configuration.Configuration=WebConfigurationManager.OpenWebConfiguration()
  2.  
give me error like this in windows application while try to read connection string in c:\inetpub\wwwr oot\site\web.co nfig- on windows server 2008

Expand|Select|Wrap|Line Numbers
  1. NullReferenceexception was caught
  2. object reference not set to an instance of an object
  3.  
and your other post i try this-

Expand|Select|Wrap|Line Numbers
  1. Dim webStr As Configuration.Configuration=WebConfigurationManager.OpenWebConfiguration("/site")
will cause
Expand|Select|Wrap|Line Numbers
  1. Failed to map the path '/site'
and with below
Expand|Select|Wrap|Line Numbers
  1. Dim webStr As Configuration.Configuration=WebConfigurationManager.OpenWebConfiguration("~/")
will tell that -
Expand|Select|Wrap|Line Numbers
  1. the application relative virtual path '~/' is not allowed here
and the last one
Expand|Select|Wrap|Line Numbers
  1. Dim webStr As Configuration.Configuration=WebConfigurationManager.OpenWebConfiguration()
will give message at compile or debug time that
Expand|Select|Wrap|Line Numbers
  1. Overlaod resolution failed becuae no accessible 'OpenWebConfiguration' accepts this number of of a arguments.
so i am helpless ;)
Jan 19 '10 #5
gr8Ashish
9 New Member
ok can you tell me how to read the web.config file's configuration section from getsection method

?


? pls giv me example
Jan 25 '10 #6

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

Similar topics

4
447
by: Programmer | last post by:
Hi everyone Well here is my problem I hope you can help me
3
2619
by: Mustaq | last post by:
Hi, How to read same config file from different application? I have 4 application in VB.NET, all are using different app.config files. NOW I need all to read only one config file, how can I do this. Thanks in Adv. Regards,
9
8281
by: ALI-R | last post by:
Hi,, I have two questions : 1) Is it mandatory that config file of a desktop application must be App.config 2) Is it possible to update config file in your code?? thanks for your help. ALI
5
10538
by: BPearson | last post by:
Hello I would like to have several sites share a single web.config file. To accomplish this, I would point the root of these sites to the same folder. Is there any reason why I might not want to do this? (IIS 5 or 6 In case you're wondering why I would do this, we have many web sites on a single server, and there are groups of sites that need to share common configuration information. I'd like to ease some administration by having one...
7
3351
by: Bob | last post by:
It's great that VS.NET makes it so effortless to add a web reference to a web service. The problem is, I haven't figured out a way to configure the URLs (or simply switch the references to another web reference) easily when I move my app from development, to staging, to production, as I have corresponding environments for the web services too. So far what I have done is copying the Reference.cs file out and creating a separate class by...
9
6480
by: Benny Ng | last post by:
Hi,all, How to let the sub-directory to avoid the authentication control from Root's webconfig? I heard that we can add a new web.config to the sub-directory. And then we can slove the problem. Virtual directory is £ºhttp://localhost/main Sub-directory is : http://localhost/main/reminder
2
4757
by: Luke Dalessandro | last post by:
I have an application with the following layout /root/ /root/Default.aspx /root/web.config /root/child/ /root/child/web.config web.config has a custom configuration section "testSection" with the
2
5423
by: rrossney | last post by:
Please look at the "what I've already done" section of this message before responding to it: I believe that I've done everything that the people who experience this error are typically told to do. I have created an ASP.NET web service that I have running on my development machine, and am trying to get it to run on my test server. Both machines are running Windows 2000 SP4, IIS 5, and the .NET 2.0 framework. When I attempt to access...
8
1973
by: theWizard1 | last post by:
Using Asp.NET 1.1, and C#. I have a directory for the website, and a directory under it named Secure. I have a web.config in each of the above directories. The web.config in the Secure directory contains the connection string information for the database. How can I use ConfigurationSettings.AppSettings to show the path of the Secure directory when getting the connection string?
1
1439
by: John | last post by:
Hi, Trying to troubleshoot a web app. I'm getting the usual "set your web.config file to customErrors mode="Off"" message. Anyway, I DO have a web.config file in the root of the app, but it's not reading it because i DO have customErrors mode=Off Why won't it use this file!? Thanks
0
9711
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9593
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10595
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10343
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10335
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
6862
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5529
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4306
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3831
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.