CodeVerge.Net Beta


   Explore    Item Entry   Register  Login  
Microsoft News
Asp.Net Forums
IBM Software
Borland Forums
Adobe Forums
Novell Forums

ASP.NET Web Hosting – 3 Months Free!



Zone: > NEWSGROUP > Asp.Net Forum > windows_hosting.hosting_open_forum Tags:
Item Type: NewsGroup Date Entered: 11/2/2005 1:54:32 PM Date Modified: Subscribers: 0 Subscribe Alert
Rate It:
(NR, 0)
XPoints: N/A Replies: 1 Views: 40 Favorited: 0 Favorite
Can Reply:  No Members Can Edit: No Online: Yes
2 Items, 1 Pages 1 |< << Go >> >|
demi
Asp.Net User
Accessing AppSettings and ConnectionStrings from DesignTime11/2/2005 1:54:32 PM

0/0

I'm writing a server web control that needs to access the web.config file.  Specifically, the AppSettings (ConnectionsStrings would be nice to). 

I tried using WebConfigurationManager.AppSettings, but it doesn't work in designtime.  I had read the ASP.NET 2.0 added the ability to do this, but I can't figure out how.

Also, Is there any equivalent of doing a Server.MapPath() during designtime.  My control need access to a configurable scratch folder.  At runtime, I use a virtual directory, but at designtime, I can't figure out the physical location of the virtual directory.

Thanks,
Mark DeMichele
demi
Asp.Net User
Re: Accessing AppSettings and ConnectionStrings from DesignTime11/3/2005 1:26:01 PM

0/0

Well, I think I answered my own questions.  Here's the test code that I put in my custom control.  In order for the MapPath one to work on virtual folders that you created in IIS you need to open your project using http://localhost/myproject, and not use the file system method.  This code was tough to figure out.  I hope it helps someone.

        private String MapPath(string name)
        {
            if (Page != null && Page.Site != null && Page.Site.DesignMode)
            {
                IWebApplication app = (IWebApplication)Page.Site.GetService(typeof(IWebApplication));
                if (app != null)
                {
                    IProjectItem pItem = app.GetProjectItemFromUrl(name);
                    if (pItem != null)
                    {
                        return pItem.PhysicalPath;
                    }
                    else
                    {
                        return "URL not found in project";
                    }
                }
                return "Can not get IWebApplication at DesignTime";
            }
            else if (Page != null)//Runtime
            {
                return Page.MapPath(name);
            }
            else
            {
                return "No page to map path from";
            }
        }

       
        private String GetAppSetting(string name)
        {
            if (Page != null && Page.Site != null && Page.Site.DesignMode)
            {
                IWebApplication app = (IWebApplication)Page.Site.GetService(typeof(IWebApplication));
                if (app != null)
                {
                    Configuration config = app.OpenWebConfiguration(true);
                    if (config != null)
                    {
                        return config.AppSettings.Settings[name].Value;
                    }
                }
                return "Can not get AppSettings at DesignTime";
            }
            else //Runtime
            {
                return WebConfigurationManager.AppSettings[name];
            }
        }

2 Items, 1 Pages 1 |< << Go >> >|


Free Download:

Books:
Beginning Visual Web Programming in VB .NET: From Novice to Professional Authors: Daniel Cazzulino, Craig Bowes, Victor Garcia Aprea, Mike Clark, James Greenwood, Chris Hart, Pages: 648, Published: 2005
Visual Basic .NET Power Coding Authors: Paul Kimmel, Pages: 708, Published: 2003
IIS 6: The Complete Reference Authors: Hethe Henrickson, Scott Hofmann, Pages: 720, Published: 2003
Professional ASP.NET XML with C#: High level, practical focus on the use of XML in professional quality ASP.NET applications. Authors: Michael Palermo, Chris Knowles, Darshan Singh, Steve Mohr, Pieter Siegers, Pages: 400, Published: 2002
Beginning ASP.NET 2.0 in VB 2005: From Novice to Professional Authors: Matthew MacDonald, Pages: 1063, Published: 2006
Beginning ASP.NET 2.0 in C# 2005: From Novice to Professional Authors: Matthew MacDonald, Pages: 1148, Published: 2006
Building Client/server Applications with VB .NET: An Example-Driven Approach Authors: Jeff Levinson, Pages: 597, Published: 2003

Web:
Accessing AppSettings and ConnectionStrings from DesignTime - ASP ... Accessing AppSettings and ConnectionStrings from DesignTime. Last post 11-03- 2005 9:26 AM by demi. 1 replies. Sort Posts: ...
Connectionstrings in ASP.NET 2.0 . Accessing the ConnString should preferably be wrapped in some sort of ... The connectionstring I have added can't be used by GUI designtime ...
appSettings Element Microsoft Access database connection. .... Accordingly, the Provider element of a connection string is necessary for design-time purposes. ...
How do I set connection string of control to appSetting key of web ... ConnectionString) to use the ActiveConnection of appSettings in web.config (see ... the same thing but in design time using the control's connection string: ...
Configuration Manager - possible bug? - MSDN Forums By this I mean using ConnectionStrings.ConnectionString in the above instead of AppSettings.Settings. You can access the connection string using the exact ...
Expression Builders in ASP.NET 2.0 The expression prefix defines the type of expression, such as AppSettings, ConnectionStrings, or String resources. Following the colon (:) is the actual ...
Web Application Settings in ASP.NET 2.0: ASP Alliance All settings can be managed easily at design time through Visual Studio 2005 tools. ..... Hayden, D., "Encrypt Connection Strings AppSettings and Web. ...
Errors: Type Abstract and Key in appSettings does not exist - Thea ... ConnectionString' does not exist in the appSettings configuration section." ... which means it doesn't even access the web.config file anymore, ...
CodeProject: Strategy to distribute secure database connection ... Microsoft suggests putting these connection strings in config files and .... Now I need to give a graphics designer access to my .aspx files so they can ...
Strongly typed DataSet connection string - ASP.NET Forums I am writing a data access layer for a database which will be used in a ...




Search This Site:










can i do this in .net

gc.suppressfinalize(me)

downloading excel ...

how can i inhirit an xml document?

asp:label to uppercase

how to hide asp:button if gridview returns no rows?

any recommended communication tools for web applicaitons

how to process a form stored in a db as an aspx page?

calendar application

using redirectfromloginpage

catch all validation message

xhtml...

server.mappath()

changing the language

asp programming not running, dll problem

best collection for comparing data...

is refresh a postback?

difference between passing by reference and value

request help

determine debug/release mode

get first letter in a textbox

connection pooling

help!! i dont want frames in my site!

wmi connection error to remote machine

wondering how i should approach this one...reducing code bloat

dropdown list

wrap text

override a class

including a .html file inside the aspx file

a simple question about code structure and code placement.

  Privacy | Contact Us
All Times Are GMT