Web.config Transform Issue with Azure Project Deployment - c#

I have a .net MVC project that i'm attempting to deploy directly to Azure using the publish settings file. I can publish locally without an issue, however when attempting to publish to Azure, it appears to be trying to transform the web.config files within subfolders (which don't have transforms, and don't need them). I receive the following error:
Transformed Web.config using C:\Projects\Git\Web.Project\Web.Debug.config into obj\Debug\TransformWebConfig\transformed\Web.config.
C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\Microsoft\VisualStudio\v15.0\Web\Microsoft.Web.Publishing.targets(2311,5): Error : Could not open Source file: Could not find a part of the path 'C:\Projects\Git\Web.Project\App_Plugins\PluginName\Web.config;\App_Plugins\PluginName\Web.config'.
The web.config referenced does exist (I've verified) and this error, as mentioned, is not thrown when publishing to a local folder.
Any suggestions as to why this is occurring and how to fix it?
Edited: Added contents of web.debug file below
<?xml version="1.0" encoding="utf-8"?>
<!-- For more information on using web.config transformation visit http://go.microsoft.com/fwlink/?LinkId=125889 -->
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
<!--
In the example below, the "SetAttributes" transform will change the value of
"connectionString" to use "ReleaseSQLServer" only when the "Match" locator
finds an attribute "name" that has a value of "MyDB".
<connectionStrings>
<add name="MyDB"
connectionString="Data Source=ReleaseSQLServer;Initial Catalog=MyReleaseDB;Integrated Security=True"
xdt:Transform="SetAttributes" xdt:Locator="Match(name)"/>
</connectionStrings>
-->
<system.web>
<!--
In the example below, the "Replace" transform will replace the entire
<customErrors> section of your web.config file.
Note that because there is only one customErrors section under the
<system.web> node, there is no need to use the "xdt:Locator" attribute.
<customErrors defaultRedirect="GenericError.htm"
mode="RemoteOnly" xdt:Transform="Replace">
<error statusCode="500" redirect="InternalError.htm"/>
</customErrors>
-->
</system.web>
</configuration>

According to your description, you could go to .net project in visual studio and right click Property on the web.config.
Set your Build Action to Content. This means that there will be no transform on this config, usual configuration is compile.
i'm attempting to deploy directly to Azure using the publish settings file.
To achieve you requirement, you could refer to import publish settings and deploy to Azure.
Step 1: Create the publish settings file in azure app service.
Click Get publish profile and save the profile locally.
Step 2: Import the publish settings in Visual Studio and deploy
After deploying, you could visit it successfully through browser.

Related

How to deploy ASP.net website on somee.com?

I am trying to deploy sample website on somee.com using free hosting.
First I published my website as a folder. I already tested on my local machine on IIS 7 in my local machine. That is working fine without any problem.
1. I created new free hosting domain on somee.com, then in file manager ->
2. Then I make a zip folder for my published website folder
3. Then I upload the zip folder and select upload and unzip archives
4. Now this is my root folder file structure
5. I hope it will run the default.aspx file. Then I try to visit my site it throws error like below
Error msg
Server Error in '/' Application.
Compilation Error
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.
Compiler Error Message: CS0016: Could not write to output file 'c:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\root\b2d18bbc\3889fee\App_Web_home.master.cdcab7d2.cugbgmun.dll' -- 'Access is denied. '
Source Error:
[No relevant source lines]
Note
I created one small default.htm file for testing. If I upload that file. That's working fine.
Web.config file
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.web>
<customErrors mode="Off"/>
<compilation targetFramework="4.5" />
<httpRuntime targetFramework="4.5" />
</system.web>
</configuration>
If I add the default.aspx file as a start up page on web config like below,
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.webServer>
<defaultDocument>
<files>
<add value="Default.aspx" />
</files>
</defaultDocument>
</system.webServer>
<system.web>
<customErrors mode="Off"/>
<compilation targetFramework="4.5" />
<httpRuntime targetFramework="4.5" />
</system.web>
</configuration>
Error msg
500 - Internal server error.
There is a problem with the resource you are looking for, and it cannot be displayed.
Here are steps to publish your .net to the server:
Please open your project with Visual Studio tool
On the Solution Explorer windows (which is normally located on the top right hand corner of the VS tool), right click your project and select Publish
Please kindly publish it to a local folder, such as C:\Project
Please just upload whatever files/folders you see on C:\Project to the server via FTP and your site will work fine.
The steps will remain the same. If you face 500 internal server error, please ask somee to check full error message on the server.
In Web.confilg file turn on the customErrors
<system.web>
<customErrors mode="On">
</system.web>
now add connection string carefully .Only change provider connection value
<add name="DBModel" connectionString="metadata=res://*/Models.Model1.csdl|res://*/Models.Model1.ssdl|res://*/Models.Model1.msl;provider=System.Data.SqlClient;**provider connection string**='your database connection path'" providerName="System.Data.EntityClient" />

Multiple config files

.net C# visual studio
In our application we are using a single config file that has all the entries to our application
specific.
Now for release to production I need to add some extra entries to config file which should be just release
specific and not needed in development.
If it was just connection strings I could have added
`<connectionStrings configSource="Configuration\ConnectionStrings.config">
</connectionStrings>`
But I have some other entries like for example:
`<system.web>
<authorization />
<machineKey validationKey=""/>
</system.web>
<system.webServer>
<modules>
</modules>
</system.webServer>`
and some more.
So how can I configure my application to use one config file for dev and separate for production.
Thanks

when does web.debug.config apply?

I have a project which has a normal web.config with the following appsettings:
<add key="CachingEnabled" value="true"/>
<add key="IsDeployed" value="true"/>
In my web.debug.config I have tried to overwrite these settings with
<add key="CachingEnabled" value="false" xdt:Transform="SetAttributes" xdt:Locator="Match(key)"/>
<add key="IsDeployed" value="false" xdt:Transform="SetAttributes" xdt:Locator="Match(key)"/>
And I also put the corresponding values in the web.release.config
However, when I step through my code, these values are still the same as the ones in the main web.config
Do these values only apply if you deploy the site in debug mode or should they work if you are just running the site locally? I am running the site locally through iis rather than by pressing the play button in visual studio if that makes any difference.
These values don't apply to anything, what happens is as part of the publish command VS transforms your default web.config using the rules you have defined in your build-specific web.config (in your case, your debug build config).
A lot of people get confused thinking that these values just automagically work when you build your project, that's not the case. However, if you want this behaviour there is a nice little plugin called SlowCheetah that will do this for you.
It's worth reading up on Web.config File Transformations and How to: Transform Web.config When Deploying a Web Application Project
The web.debug.config or web.release.config are only consumed by web deployment to transform web.config, say "Build deployment package" or "Publish". Regular build/debug doesn't invoke transform.
SlowCheetah may be able to help you: http://visualstudiogallery.msdn.microsoft.com/69023d00-a4f9-4a34-a6cd-7e854ba318b5

ConnectionString for assemblies

I have a website with a connection string listed in its web.config. The connection string is altered by the Publish feature so that it can reference a development database until it is released, when it references a separate release database.
The website accesses the databases through some assemblies, though. They are Class Libraries so they can't be Published, at least as far as I can tell. I read that the web.config would override the app.config connectionstrings, but that doesn't seem to be happening.
Whenever I Publish the release site references the development database, unless I alter the assemblies app.config files to reference the release database.
I don't want to have to remember to do that every time. How do I handle this?
You've got two issues here:
1. How to remember to publish the correct settings each time you publish:
One way to deploy such settings is by using web.config transformations in Visual Studio. This is pretty easy to set up and means that you do not have to remember to update the settings each time you publish.
As well as debug and release environments, you can also create transforms for "UAT", "Staging", "Beta" or whatever other configs you might need.
You might find these articles useful: here, here and here.
For example, here is a transform for a Release environment:
<?xml version="1.0"?>
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
<connectionStrings>
<add name="MyDB"
connectionString="Data Source=ReleaseSQLServer;Initial Catalog=MyReleaseDB;Integrated Security=True"
xdt:Transform="SetAttributes" xdt:Locator="Match(name)"/>
</connectionStrings>
<system.web>
<compilation xdt:Transform="RemoveAttributes(debug)" />
<customErrors defaultRedirect="GenericError.htm"
mode="RemoteOnly" xdt:Transform="Replace">
<error statusCode="500" redirect="InternalError.htm"/>
</customErrors>
</system.web>
</configuration>
Above, you will see that the transform for Release mode sets the attributes of the MyDB connection string (xdt:Transform="SetAttributes"), removes the debug attribute from the compilation section and replaces the customErrors section with a new version.
It's a simple, yet very powerful technique.
2. How to get your assemblies to pick up the settings in the web.config
If your libraries have been written in the usual way, they should be retrieving their connection strings by simply accessing the [Web]ConfigurationManager.ConnectionStrings property. Like #Bob Horn says, they should then pick up the settings from the host process's config file (in this case the web.config of your web app).
However, sometimes you might find that a library is getting its settings from a .Settings file in the project, in which case things get a little more complicated. You will need to copy the settings section of the app.config in to the web.config. (You can also do this using the transforms technology described above.)
If you have access to the source code of the other assemblies, find the part of the code that retrieves connection strings. If it's not accessing the ConfigurationManager class, then that might explain why it's not picking up the web.config file.

How does web.config files works in C# works?

Let's say that in my main startup project I have web.config file with some setting:
<!-- ... -->
<appSettings>
<add key="Setting" value="setMe!" />
</appSettings>
<!-- ... -->
This project has two configurations: Release and Debug. Each transforms this setting to its own value, for example web.Debug.config:
<!-- ... -->
<appSettings xdt:Transform="Replace">
<add key="Setting" value="debugValue" />
</appSettings>
<!-- ... -->
When I compile it there is no transformed config file. I have only three files: web.config, web.Debug.config and web.Release.config.
You have to publish your project ("Publish Web Site" command) and your destination (IIS) will use the correct web.config file with your Release configuration.
Configuration transformation is only done when publishing. Your base configuration file should have your development settings. If you choose to use the default build configurations, normally the release transform file should contain your production environment settings and the debug transform file will contain your test environment settings.
Personally, I usually create a new build configuration for testing and for production and leave the debug and release transforms empty.

Categories

Resources