I use Visual Studio for Website development (VS 2010 Ultimate and VS 2012 Professional). To be more specific, I created this website by File > New Web Site, so I do not believe this is a project.
While developing the website, I have debug="true" enabled in the web.config file. When I publish, I manually change to debug="false".
<configuration>
<system.web>
<compilation debug="true" strict="true" explicit="true" targetFramework="4.5">
</system.web>
</configuration>
There are two config files in the solution: "web.config" and "web.Debug.config".
This is what the various forum articles and "Programming ASP.NET" books say to do, but I wonder if there is a way to have debug="true" for local development and automatically switch to debug="false" when using Build > Publish Web Site so I don't have to manually change the web.config file?
According to this forum answer, "There is no way to have a Release configuration for your website."
Keeping in mind that this is a Web Site and not a project, it looks like adding another config based on comment suggestions might not be possible. A possibly valid answer is "no, it is not possible in this context."
Is there another way to achieve the intended outcome without using the current workaround of manually changing the debug setting?
Sorry, it's related to it being a "web site" type project, which aren't compiled:
Configuration of publishing an ASP.NET web site
To quote the previous responder above:
"Web Site projects don't have the Release configuration available, but it makes no difference since they are not compiled. Web Application projects, on the other hand, do get compiled and have both configurations available."
According to the available references, for "ASP.NET Website" it is not possible to have a separate release configuration.
So the answer to the posed question is no: it is not currently possible. Manually changing the debug attribute when you publish and then changing it back is the only option in that case.
How can you proceed? If you really need to have a release configuration and a debug configuration, the a possible option is Converting a Web Site Project to a Web Application Project. While not a direct answer to the presented question, it is an alternative.
For some projects I've set up an Environment appSetting and scoped all other keys off of that Environment.
For instance:
<add key="Environment" value="Development"/>
<add key="Development.Title" value="My Dev App"/>
<add key="Production.Title" value="My Production App"/>
<connectionStrings>
<add name="DbContext.Development" connectionString="Initial Catalog=DatabaseDev;...."
providerName="System.Data.SqlClient" />
<add name="DbContext.Production" connectionString="Initial Catalog=DatabaseProd;...."
providerName="System.Data.SqlClient" />
</connectionStrings>
Then you would create a Configuration class that would pull appSettings and connectionStrings by looking for:
appSetting
string.Format("{0}.Title", ConfigurationManager.AppSettings["Environment"])
connectionString
string.Format("DbContext.{0}", ConfigurationManager.AppSettings["Environment"])
Not perfect but this will let you only have to replace one web.config value instead of a bunch without the help of the Publish config transform.
Related
I consumed about deployment for my projects. For example I am developing a asp.net web api or asp.net mvc project on visual studio. I use local database and local file usernames and password for ssl. I finish the development and publis it on my local iis server and see the working application. After local iis test, I load it to server but sometimes forget the change web.config settings, connectionstrings, ssl certificate paths and password. So the working server application that users accessed fails. How can I solve this problems?
What I do is I replace the configuration in the Web.Release.config using Transform
So if for example in my Web.config I have the following connection string:
<connectionStrings>
<add name="DefaultConnection" connectionString="Data Source=(LocalDb)\v11.0;AttachDbFilename=|DataDirectory|\sample.mdf;Initial Catalog=sample;Integrated Security=True" providerName="System.Data.SqlClient" />
</connectionStrings>
In my Web.Replace.config I update the connectionString for production like this:
<connectionStrings xdt:Transform="Replace">
<add name="DefaultConnection" connectionString="SERVER_CONNECTION" providerName="System.Data.SqlClient" />
</connectionStrings>
Though keep in mind that the Transformation that I did in Web.Replace.config only applies when you publish your web app. You won't be able to test it locally by just running your application in Debug/Release mode
You should implement Web.Config transformation. Check this MSDN link for more information.
Just to give an overview - by implementing Web.config transformation, your project will have different Web.Config file (For example, Web.config, Web.Live.config, Web.PreProd.Config, etc), i.e., each different file for diffrent build configurations. The main web.config should remain as it is. Its just the other config files where you will need to specify the configurations which you want to overwrite. Once done, if you publish with a particular build configuration, then the newly generated web.config (in publish folder) should have all configurations from web.config + the differences you would have specified in the transformed file for that build configuration.
Good day!
After watching a video I was able to summarize the steps I needed as such:
Steps in configuring and deploying to IIS ASP.NET
1. Create directory
example:
C:/inetpub/wwwroot/mvcauction
Open internet information services Manager
Right-click default website
Add application.
Choose website name.
example mvcauction
Paste the directory you created in step 1.
Click select button.
Make sure that the property has .net framework version 4.0
Click ok.
Go to your visual studio IDE.
Righ-click on the project file in the solution explorer.
CLick publish
Click publish profile drop down and select new. Add a profile name.
Example:
Local IIS Website
Choose publish method File System
Use step one's directory for the Target location
configuarion: Release
Choose local IIS Website.
Expect an error.
Open visual studio command prompt.
Execute this command: sqllocaldb share v11.0 IIS_DB
Update your web config. Refer to the paint screenshot.
Publish again in iis manager.
if not yet ok:
Go to visual studio again.
Open data base explorer.
Right-Click to data connections to add connection.
For the server name: Enter the value that we are using in the config file data source.
Example
(LocalDB).\IIS_DB
Click ok
Righ-Click on the new connection added.'
Choose new query.
Execute the shown commands.
Go to the browser and refresh.
However I cannot finish step 21 which I conclude is because the tutorial did not use oracle database as its data source. I cannot publish my visual studio project successfully. So, please, does anyone here know what to put in the web config file?
This is my web config file:
<configuration>
<system.web>
<compilation debug="true" strict="false" explicit="true" targetFramework="4.5" />
<httpRuntime targetFramework="4.5" />
</system.web>
<connectionStrings>
<add name="OracleConnectionString" connectionString="Data Source=localhost;USER ID=userid;PASSWORD=password"
providerName="Oracle.DataAccess.Client" />
<add name="ConnectionString" connectionString="Provider=MSDAORA;Data Source=localhost;Password=password;User ID=userid"
providerName="System.Data.OleDb" />
</connectionStrings>
<appSettings>
<add key="ValidationSettings:UnobtrusiveValidationMode" value="None" />
</appSettings>
</configuration>
I have made an MVC website in Visual Studio 2015 and it works in my localhost. But when I published my website and put into my host, it doesn't work. It gives me this error notice:
Server Error in '/' Application.
Configuration Error
Parser Error Message: The 'targetFramework' attribute in the
element of the Web.config file is used only to target
version 4.0 and later of the .NET Framework (for example,
''). The 'targetFramework'
attribute currently references a version that is later than the
installed version of the .NET Framework. Specify a valid target
version of the .NET Framework, or install the required version of the
.NET Framework.
Source Error:
An application error occurred on the server. The current custom error
settings for this application prevent the details of the application
error from being viewed remotely (for security reasons). It could,
however, be viewed by browsers running on the local server machine.
Source File: G:\xxx\xxx.com\httpdocs\web.config Line: 24
Version Information: Microsoft .NET Framework Version:4.0.30319;
ASP.NET Version:4.0.30319.34248
Related parts in my web.config:
<configSections>
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 --></configSections>
And this part with error:
<system.web>
<authentication mode="None" />
<customErrors mode="Off" />
<compilation debug="true" targetFramework="4.6" />
<httpRuntime targetFramework="4.6" />
</system.web>
Properties of my website:
And NuGet Package Manager:
EntityFramework Reference Properties:
Default Web Site Basic Settings: (To be honest, I am not sure whether I should add a new website(my website) in here.)
My installed .net frameworks:
My publish method:
I have investigated this problem on the Internet and I have found several links related to my problem: Asp.net MCV4 framework issue. In this link, there are two main offers:
changing this compilation tag
updating application pool in IIS
Actually, I have tried to change this tag but it doesn't change. Then I have controlled my application pool but it seems up-to-date.
I have called my host provider and I have explained my problem. They say that this error is not related to their servers.
What should I do? What is the solution for this?
Your website project is targeting v4.6 of the .NET Framework but your hosting provider has not yet installed this version. Your options:
Ask provider to install it - they are unlikely to do this.
Find another provider that does support it.
Change your project to target v4.5.
I'm adding one more information to complement DavidG's answer. If Internet Information Server (IIS) is your provider then Web Platform Installer (an IIS extension) is a very helpful tool. It can your best bet to check the current state of what all components are installed on your machine (Refer screenshot)
It is very easy to check what all components are missing from your computer. Based on that, you can kick-start installation of any missing component through the UI of this IIS extension itself.
I just had a similar problem following the installation ( windows update) of the KB 3205402.
Big difference with my case: the application worked well before the update !
==> I found in "IIS Manager", in "ISAPI and CGI Restrictions", that the framework ASP.NET v4.0.30319 has been switched to "unauthorized" !
Switching it to "Authorized" resolved my problem
I changed:
<system.web>
<compilation debug="true" targetFramework="4.7" />
<httpRuntime targetFramework="4.7" />
<customErrors mode="Off"/>
</system.web>
to
<system.web>
<compilation debug="true" targetFramework="4.5" />
<httpRuntime targetFramework="4.5" />
<customErrors mode="Off"/>
</system.web>
i.e, changed targetFramework value to 4.5 (the one supported on server) from 4.7. and worked.
had the same issue on the below line on an offline server ,
<compilation targetFramework="4.5.2">
tried adding all the roles and features related to .Net framework from the server manager and to its pool ,
but didn't work , what worked for me is just downloading Microsoft .NET Framework 4.5.2(Offline Installer)
I went round and round with this today with no resolution. Exasperated, I finally just deleted my working copy from my drive, and rechecked it out from SVN.
Fixed.
Not a particularly clever answer, but it fixed it for me, no idea what the actual problem was.
I tried replacing the targetFramework 4.5.2 to targetFramework 4.0 directly in config file. Then it and all the functions work correctly.
Before:
<compilation targetFramework="4.5.2">
After:
<compilation targetFramework="4.0">
I've got a .NET Web API project and on load I'm getting a download of this script called browserLink.
http://localhost:49818/ea93983f23c54f35a63de09646c09159/browserLink
Its associated with .NET Signalr but I'm not using that so I'm not sure why its being included. Any ideas how to turn it off?
Disable Browser Link in Visual Studio 2013.
Do this by editing your web.config file to add the following line to your appSettings section:
<appSettings>
<add key="vs:EnableBrowserLink" value="false"/>
</appSettings>
Note that Browser Link is only used when working in Visual Studio AND the web application is compiled in debug mode, i.e.:
<system.web>
<compilation debug="true" />
</system.web>
In other words, end-users of your site will never make this request.
I did a couple google searches about this and am not finding anything, so I thought I'd ask here.
I'm working on our internal CMS and I noticed that we're getting live data back when doing debugging because of our web services instead of the dev data that I wanted. It doesn't do this on our dev CMS website, but we're trying to do all our development on localhost. Is there any way to set up an environment variable in our web config for the URL so that the CMS points to the dev database instead of live database that is referenced in the wsdl files?
You can use the appSettings portion of the web config to for configuration information.
In the configuration section of the Web.config you will find the appSettings section:
<appSettings>
<add key="Key" value="Some Value"/>
</appSettings>
In code you can read in the value like this:
var someValue = ConfigurationManager.AppSettings["Key"];
+1 for Dan's method of storing the URL. To use this URL at runtime just update the URL property of your web service proxy object with the value from your web.config.
MyClientClass o = new MyClientClass();
o.Url = varFromWebConfig;
o.MyWebMethod();
Actually, one of my coworkers suggested an alternate way of solving this issue which seems even better to me: fixing it server-side, rather than client side like I've been trying and has been suggested here. His suggestion was to create a subdomain in IIS on all of our servers that points to the web service folder and then put host files for the appropriate web server on my local machine. This seems like the ideal solution to me since it wouldn't require changing all the current web service proxy objects like the client side solution would, just the web service consumption within App_WebReferences.
YES!!! USE Web.config transforms
Web.config contains the configuration that will run in your IDE while debugging:
<configuration>
<appSettings>
<add key="Service.Name" value="http://debugserverURI/Service.asmx"/>
</appSettings>
</configuration>
On publish in "Release" mode, transforms in Web.Release.config will be applied:
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
<appSettings>
<!--point to production server -->
<add key="Service.Name" value="http://PRODUCTIONserverURI/Service.asmx"
xdt:Transform="SetAttributes" xdt:Locator="Match(key)"/>
</appSettings>
</configuration>
You can do the same for Web.[whatever_build_you_want].config, if you support both test and prod servers.