I have a site and I want to use the web.config of my site and not the one from root web.config.
I'm trying to access to the ConnectionStrings located in the web.config of my site, but writing this line:
var connectionString = System.Configuration.ConfigurationManager.ConnectionStrings;
I access to the root web.config of the server and it has connectionString like:
data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|aspnetdb.mdf;User Instance=true
I also tried WebConfigurationManager, with the same results:
var connectionString = WebConfigurationManager.ConnectionStrings;
What can I do to access my site's web.config and not the root one?
Thanks in advance for any help
Related
I have developed a new website using a CMS named Kentico.
After being published on my web server named web3, it consists of 2 folders: a folder for the live site (named live) and one server for the admin site (named admin).
My folder structure looks like:
For the time being, my IIS installation looks like:
So i have created an application for the live site pointing to the live folder and an application for the admin site pointing to the admin folder in the Default Web Site of IIS.
Therefore, the URLs to access the websites are http://web3.domain.org/Live and http://web3.domain.org/Admin.
It works fine but I want to access the live site at http://web3.domain.org/ and the admin site as it is now: http://web3.domain.org/Admin.
One solution I found was to create a new website in IIS pointing to the live folder and add a new application inside it pointing to the admin folder:
It works fine, the live site is accessible at http://web3.domain.org/ and the admin site at http://web3.domain.org/Admin.
However, I am not sure if it is the best option as the admin site is now dependent of the live site. If the live site is down, I won't have access to the admin site while they are technically independent (2 distinct folders).
I also tried to keep using the Default web site with some rewrite rules in a web.config under wwwrooot like :
<rules>
<rule name="Root_URL_Rewrite" stopProcessing="true">
<match url="^(.*)" />
<action type="Rewrite" url="/Live/{R:0}" />
</rule>
</rules>
but it didn't work.
Your help would be welcome.
I would recommend creating two separate IIS sites. One for the admin app (e.g. admin.something.com) and second IIS site for the live app (something.com). Or, if you want to have both apps on the same domain name and the admin app in a subfolder, then you need to use one IIS site - this will be set to the live app and then create a virtual application subfolder and point it to the admin app. So, you will have basically nested admin app - this is not recommended as in some cases IIS can detect two web.config files as nested and it could cause issues. Or, IIS will take the live site's config file as master and ignore the nested one, etc. I would vote for two separate IIS sites.
I currently have a web service which I would like to host publicly but my company policy is against exposing the web.config file outside of our company firewall. Is there a way where I can host my web service on a public server securely?
Thanks to how IIS works, your web.config file won't be accessible from outside your application. You won't be able to get to it by just browsing directly to it unless you manually allow that action such as enabling directory browsing etc.
The web.config file is more an IIS config than anything else, as it merely configured the IIS environment to run the application as you intend it to.
You have nothing to worry about
My web app have two webconfig file like this
root
|
|-subsystem
|web.config
web.config
Almost system had config use azure session ok, but my sub system cannot store session to azure. always null
I had copy same connection setting for sub webconfig file, but not work.
can you give me some advice
The root cause is IIS version.
With dev environment IIS express not store session to redis. But my server with IIS 8.5 , it work!
We are creating an azure angularjs application. This application is created as a web role in an azure project. After a deploy we get a 403 error:
403 - Forbidden: Access is denied.
You do not have permission to view this directory or page using the credentials that you supplied.
All files are copied automatically from the source project via Gulp. They are not included in the project file.
In the project properties we specified in the publish settings that it should "copy all files in this project folder". The main page is an index.html page that should load up the whole angular application. To get the index.html as default page we added this to the web.config:
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
<defaultDocument>
<files>
<clear/>
<add value="index.html"/>
</files>
</defaultDocument>
Are there other settings we need to adjust?
I may not be able to point out what's wrong with your application but could you please check as following.
Just visit your website with index.html specified. I mean http://your-app.cloudapp.net/index.html. If it works then this could because your web.config setting doesn't work.
If your got a 404 error, please check the website folder via Remote Desktop. This might because your deployment script (or project setting) was incorrect which caused some files were missing.
If it works but got 403 when you clicked some links or buttons to navigated to another angular view, this should because your IIS doesn't support Angular Router. To fix this problem please refer How do I configure IIS for URL Rewriting an AngularJS application in HTML5 mode?
Hope this helps
I have a SharePoint 2010 site and a custom web application. End goal is to be able to use cross-site JavaScript. They use different .net Frameworks so need to be separate IIS sites.
How can I host both under http://website.com and http://website.com/site2 for example?
I have tried using one site inside the other as an application using a different application pool but have issues with the web.config files because of the duplicate references needed.
Try and create a new app pool for the /site2 site. Then set the App Pool attribute enableConfigurationOverride to false. This can only be done in appcmd or by editing the IIS Config file manually. Appcmd command is this:
appcmd.exe set config -section:system.applicationHost/applicationPools /[name='AppPoolName'].enableConfigurationOverride:"False" /commit:apphost
This will tell the sub site app pool to not import any settings from the parent web.config.
I was able to run a MVC site underneath a SharePoint site with this configuration.