Avatar of vensali
vensali
Flag for India asked on

Reading from web configuration file

I can read connection string from webconfig file  from visual studio from the below mentioned code
in login.aspx page

 Private constr As String
    Private rootWebConfig As System.Configuration.Configuration
    Private connString As System.Configuration.ConnectionStringSettings

rootWebConfig = System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration("/WEBUI")    where WEBUI is project folder where webconfig resides.

        connString = rootWebConfig.ConnectionStrings.ConnectionStrings("Sqlserver")
        constr = connString.ConnectionString

I created  web deploy package and imported into localhost IIS 7. import application worked fine. when I tried to browse the login.aspx from IIS published folder I get the following msg

Server Error in '/KHWEB' Application.  -  KHWEB  web application name in IIS7

Object reference not set to an instance of an object.
ASP.NETMicrosoft IIS Web Server

Avatar of undefined
Last Comment
vensali

8/22/2022 - Mon
jorge_toriz

Can you try with the following change?

OpenWebConfiguration("./WEBUI")
ASKER CERTIFIED SOLUTION
vensali

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
vensali

ASKER
I could solve the problem by giving   my web application name ( "/ App name")  hosted in iis in open configuration.
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck