No owin.Environment item was found in the context - asp.net

Microsoft recently introduced new ASP.NET Identity - replacement for old (Simple)Membership. Unfortunately, I can't use this new membership system in my old project because it throws System.InvalidOperationException: No owin.Environment item was found in the context. This is a known bug, but Microsoft keeps silence about this issue. The easiest way to reproduce this bug - it's to create a new web application (MVC, WebForms or WebApi - doesn't matter) in VS 2013 (with Web Tools 2013 Preview Refresh) and then go to the login page. It will work. Then change namespace in your application to anything else than original namespace and login page will throw that error. Changing namespace back to original (the one you used at the creation of a project) will solve this problem.
It looks like .net stores somewhere something related to the original namespace, but I can't find what and where, it's not in the project folder. I know that stackoverflow is not a place for a bug reports, I just hoping that someone already found a solution for this issue or maybe people involved in the development of ASP.NET Identity will see this.

Most likely it cannot find the OWIN Startup class. The default convention for the Startup class is [AssemblyName].Startup. If you're no longer following that convention you'll need to specify the full name of your Startup class in the Web.Config.
The next release of Microsoft.Owin.Host.SystemWeb package now throws detailed exception messages when the Startup class cannot be found.

I had the same issue, it was fixed after making sure this line was in web.config:
<add key="owin:AutomaticAppStartup" value="true" />

I had the exact same error, but as it turned out I had another configuration problem in my web.config. My web.config was missing the attribute defaultLanguage="c#" in the compilation element under system.web.
In this case it will default to VB. So unless you have your Startup class written in VB you should change the default language to C#.
Not correct:
<compilation debug="true" optimizeCompilations="true" targetFramework="4.6.1">
This is correct (unless you use VB):
<compilation debug="true" defaultLanguage="c#" optimizeCompilations="true" targetFramework="4.6.1">

Cleaning ASP.NET temporary files helped me with this exact problem

I created two new projects called TesteMvc5.2 and TesteMvc5.0 and both of them didn't work at start
this is because the default namespace is different from the assembly name.
but after I put the line
<add key="owin:AppStartup" value="TesteMvc5._2.Startup, TesteMvc5.2" />
on the web.config it worked fine.

I tried everything mentioned on this page but nothing worked. Then I found out about a setting in IIS named owin:AutomaticAppStartup. You can find it in the Application Settings page of the IIS Manager for the Default Web Site. Check to see if that setting is true. If not set to true. This worked for me.
This is the website where I found the answer:
http://gotoanswer.stanford.edu/?q=Microsoft.Owin.Host.SystemWeb+and+still+getting+No+owin.Environment+item+was+found+in+the+context

If you happened to have copied the below config from MVC4, you should remove it from web.config
<add key="owin:AutomaticAppStartup" value="false" />

I had this same issue. I fixed it with the web.config.
However I had changed the assembly name and namespace and did not find the original assembly name anywhere anymore.
I then discovered that clean was not removing the original assembly from the bin.
Aftter deleting the bin litter, I was able to remove the web.config OWIN entry.

None of the above answers worked for me.
Turned out my project was missing the "Startup" class that contains the following:
using Microsoft.Owin;
using Owin;
[assembly: OwinStartupAttribute(typeof(NAMESPACE.Startup))]
namespace NAMESPACE
{
public partial class Startup
{
public void Configuration(IAppBuilder app)
{
ConfigureAuth(app);
}
}
}
This file called "Startup.cs" is located on the root folder (~/) of your project.
My "Web.config" doesn't have any of this "Owin" configuration posted on the other replies.

Had same problem. Thanks for the shared solutions.
this..
<add key="owin.AppStartup" value="Namespace.Startup, Namespace"/>
<add key="owin:AutomaticAppStartup" value="false"/>
fixed for me

I have no idea why this works but it did!
My problem was in VS2013. In the WebConfig, debug was set to true and I got that error. When I set it to false it worked fine and then I reset to true and it continued to work OK!
At first when debug was true before changing to false, I put a break point in my StartUp code and it wasn't reached at all. After changing to false pressing save and then back to true the StartUp code was called and the program works like it should.

I experienced this error in an Optimizely (Episerver) solution where I had two feature branches using the same CMS database. In one feature branch I was working on a proof of concept using a visitor criterion. So I had created something like this:
public class SomeVisitorCriterionSettings : CriterionModelBase
{
public override ICriterionModel Copy()
{
return base.ShallowCopy();
}
}
[VisitorGroupCriterion(
Category = "Some category",
DisplayName = "My visitor criterion")]
public class SomeVisitorCriterion : CriterionBase<SomeVisitorCriterionSettings>
{
public override bool IsMatch(IPrincipal principal, HttpContextBase httpContext)
{
// match logic here..
}
}
And within Episerver -> CMS -> Visitor Groups I had created an instance of this visitor criterion. After switching to the other branch where this code did not exist, but the instance in the database did, the Owin exception was thrown.
Deleting the visitor criterion in the CMS resolved the issue, but I honestly have no idea why this sort of exception is thrown. I would love to know though..

I have tried all of the above suggestions, without success;
then reading the documentation at:
https://learn.microsoft.com/en-us/aspnet/aspnet/overview/owin-and-katana/owin-startup-class-detection
I understood that the error was in the call to the assembly in the Startup.cs file:
wrong code:
[assembly: OwinStartupAttribute(typeof([AssemblyName].Startup))]
right code:
[assembly: OwinStartup(typeof([AssemblyName].Startup))]
so, I fixed the error removing the word Attribute from OwinStartupAttribute

adding default language to compilation in web.config did it for me!

Related

Owin error with ASP.NET MVC application

I have an ASP.NET application that runs fine on my local machine. I just uploaded it to a server using web deploy. I'm getting the following error when I try to view the site:
The following errors occurred while attempting to load the app.
- The OwinStartup attribute discovered in assembly 'Gators3' referencing startup type 'Gators3.Startup' conflicts with the attribute in assembly 'MyFirstProject2' referencing startup type 'MyFirstProject2.Startup' because they have the same FriendlyName ''. Remove or rename one of the attributes, or reference the desired type directly.
To disable OWIN startup discovery, add the appSetting owin:AutomaticAppStartup with a value of "false" in your web.config.
To specify the OWIN startup Assembly, Class, or Method, add the appSetting owin:AppStartup with the fully qualified startup class or configuration method name in your web.config.
I tried searching the entire solution for the string "MyFirstProject2" but did not come up with anything. The message gives a couple of suggestions, but none of them mean anything to me. I don't know how to "Remove or rename one of the attributes, or reference the desired type directly," and I don't see a place in the web.config to "add the appSetting owin:AppStartup with the fully qualified startup class or configuration method name in your web.config."
I found this, but am not quite sure how to implement it. I also did find [assembly: OwinStartupAttribute(typeof(Gators3.Startup))] in my Startup.cs, but not sure what the right thing to do there is either.
The problem is that the Gators3.dll and MyFirstProject2.dll are in the same folder (I guess it is bin folder on your server) and both are using Owin middleware. If you do not need MyFirstProject2.dll then the easiest way would be to delete that assembly. If you need it, but without Owin - add following line to Web.config/app.config in your MyFirstProject2 project:
<add key="owin:AutomaticAppStartup" value="False" />
If you need to use Owin for two projects configure friendly names for both of them.
Gators3 project:
Change Owin startup attribute to something like:
attribute [assembly: OwinStartupAttribute("GatorsConfig", typeof(Gators3.Startup))]
And add following line to Web.config within appSettings section:
<add key="owin:appStartup" value="GatorsConfig" />
MyFirstProject2 project:
Change Owin startup attribute to something
like:
attribute [assembly: OwinStartupAttribute("MyFirstProject2Config", typeof(MyFirstProject2.Startup))]
And add following line to Web.config within appSettings section:
<add key="owin:appStartup" value="MyFirstProject2Config" />
I had the same issue : removing everything in the /bin folder and rebuilding the solution alone worked for me. But it could be combined with renaming your assembly attribute at the top of the startupclass, giving it a Firendly name which will help to differentiate both the startup files.
[assembly: OwinStartup("MyFriendlyNameForProject1",typeof(MyProject.Startup))]
Clear your bin folder and obj folder.Rebuild the project again and run :)
Also, if you publish a solution to Azure:
1) right click and select Publish.
2) go to Settings and expand the "File Publish Options"
3) select "Remove additional files at destination"
4) Publish
Worked for me, after deleting the files from obj and bin Folder.
Delete anything that says 'MyFirstProject2' from your bin folder and rebuild the solution, It will work.
Happens when you reference (by mistake?) a project with owin startup inside another project with owin startup. Fix - delete the reference, bin, obj folders and rebuild.
I had the same problem and i added the following tag on web config:
<appSettings>
<add key="owin:AutomaticAppStartup" value="false" />
</appSettings>
This is what I have done:
Since I have 3 projects in one solution, I had to open all bin folder of each project and delete all files there.
Build each project one by one.
Build the whole solution.
Problem solves on my part.
Remove all files in your 'bin' folder and rebuild.
Delete files Bin, Build each project one by one.
Deleted everything in the bin folder, including the roslyn folder then published, and everything worked fine.
Remove old built data in temporary files, in the following path
C:\Users\[user]\AppData\Local\Temp\Temporary ASP.NET Files\vs
In my case, I was referencing one project in the other accidentally, which is why I was getting this error after removing the one accidentally added in the main project solved the problem.

Why can't this find the namespace I'm referencing?

When I run my application it's throwing an error and highlighting this line in the web.config:
<add namespace="Telerik.Reporting" />
When I look at the references for my project, I can see that it's there and it's path is:
C:\Program Files (x86)\Telerik\Reporting Q3 2014\Bin\Telerik.Reporting.dll
In my controller, I can put using Telerik.ReportViewer.Mvc; and there's no problem. But when I try to reference it from my razor view it can't find it, and as mentioned above if I try to add the namespace from the web.config I get an error.
What am I missing here?
I had to set copy local to true for the references I had this issue with. I'm not sure if that's normal or if it's something special to do with the telerik assemblies though.

SignalR /signalr/hubs 404 Not Found

I am trying to deploy a SignalR site on IIS. Code all works fine in VS. But getting the 404 not found error trying to resolve signalr/hubs so far I have tried.
1) Changing the Script ref to:
script src="<%= ResolveUrl("~/signalr/hubs") %>" type="text/javascript"></script>
2) Modifying Web.Config to include :
<system.webServer>
<validation validateIntegratedModeConfiguration="false" />
<modules runAllManagedModulesForAllRequests="true">
</modules>
</system.webServer>
3) Changing the invoke requests on IIS for UrlMappingsModule.
4) added SignalR.Hosting.AspNet.dll to see if that would help anything.
Not sure what else to try or check, any help or point in the right direction?
The order of route registration matters. I had this exact problem and fixed it by ensuring my global.asax.cs looked like this:
public class MvcApplication : System.Web.HttpApplication
{
protected void Application_Start()
{
AreaRegistration.RegisterAllAreas();
RouteTable.Routes.MapHubs();
WebApiConfig.Register(GlobalConfiguration.Configuration);
FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
RouteConfig.RegisterRoutes(RouteTable.Routes);
}
}
This was in a web site using SignalR, MVC and WebApi all together.
The reason of this 404 error is hubs are not mapped, previously it would have to be done as answered by SimonF. If you are using SignalR version 2 RouteTable.Routes.MapHubs(); is now obsolete. For mapping hubs you can create a startup class as below.
[assembly: OwinStartup(typeof(WebApplication1.Startup))]
namespace WebApplication1
{
public class Startup
{
public void Configuration(IAppBuilder app)
{
// Any connection or hub wire up and configuration should go here
app.MapSignalR();
}
}
}
referenace : http://www.asp.net/signalr/overview/releases/upgrading-signalr-1x-projects-to-20
Try adding a wildcard application map to your server to help map the unknown extension in the script URL "~/signalr/hubs"
I was able to fix the 404 on ~/signalr/hubs by changing the following appSetting in web.config to "true".
<add key="owin:AutomaticAppStartup" value="false" />
If you are working on webforms, Please take the following steps
In the webconfig:
<validation validateIntegratedModeConfiguration="false" />
<modules runAllManagedModulesForAllRequests="true"/>
In the page add reference to hub as
<script src="/signalr/signalr/hubs"></script>
instead of
<script src="/signalr/hubs"></script>
Make sure your site's AppPool targets the correct version of .NET Framework.
I might be a little late but hope it helps someone.
Make sure this code run on start.
Sub Application_Start(ByVal sender As Object, ByVal e As EventArgs)
RouteTable.Routes.MapHubs()
End Sub
Because I added a global.asax to my application and then a codebehind but put this in Global.asax file
<%# Application Language="VB" CodeBehind = "Global.asax.vb" %> /*This was wrong*/
So when i tried to run the application, the Application_Start in my global.asax did not initialize the hub. that's why it couldn't resolve signalr/hubs
fixed with this in my Global.asax
<%# Application Inherits="_Global" Language="VB" %>
and this in my Global.asax.vb:
Public Class _Global
Inherits System.Web.HttpApplication
Check web.config, on segment AppSettings add
<add key="owin:AutomaticAppStartup " value="false" />
on Key must be white space on the end of the name key, like #Randy H.
I had no issues with routing in MVC3, but did get the path wrong. I would suggest you look at the source and see where the script is actually pointing, make sure it is resolving the application directory ok. And make sure you can physcially open the file with the correct path with your browser. E.g.
<script src="/MyWebApp/signalr/hubs" type="text/javascript"></script>
Can you open the file from a browser (replacing it with the correct subdirectory)?
If not, the hub might not be set up correct and it might point you in the right direction. Fiddler it.
The syntax I used was:
<script src="#Url.Content("~/signalr/hubs")" type="text/javascript"></script>
It might be the difference between Url.Content and ResolveUrl
Similar problem I had on IIS version, I fixed it by restarting AppPool, restart web and its working now.
there are potentially many causes of this 404 - a few common ones can be found by
Hit the url in the browser /signalr/hubs - if there is an error, you will see the full error come back.
check for duplication of HubName attribute if you have base class
ensure you have the correct version referenced in all projects (as to avoid binding errors)
For me the solution was to reinstall all the packages and restore all the dependecies.
Open nuget powershell and use this command.
Update-Package -Reinstall
I had the same problem, it was an asp.net project using signalR, it worked properly before I published but when I hosted it in IIS, it didn't.
After I inspected I realized the address /signalr/hubs is not correct, let me explain more, just do the following steps:
Open up your web application in the browser (Using IIS), you see the interface you designed, yeah? now press ctrl+U or right click on the page an select View Page Source.
You will see multiple links starting with <script> tag at the top of the page, find something like <script src="/signalr/hubs"></script> now click on it, if you are taken to the page which involves "404 - File or directory not found."you have some mistakes on defining address, find the true address and change the address in the address bar to observe the true result
In my case I needed to add my project name at the start of the address, so I had to change the address from:
<script src="/signalr/hubs"></script>
to
<script src="/MoveShape/signalr/hubs"></script>
in which MoveShape was my project name, now after pressing ctrl+U in the browser and following previously told steps, you click on the link and this time you see the true result, the page show codes starting with:
/*!
* ASP.NET SignalR JavaScript Library v2.2.2
* http://signalr.net/
*
* Copyright (c) .NET Foundation. All rights reserved.
* Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
*
*/
yeah! that's it, it works properly, keep in mind that it had no problem when I was testing it using Visual studio but not after hosting in IIS, as others have recommended make a correct address by applying <%= ResolveUrl("~/") %> or other methods.
In my case, I lose some owin dependencies then I got the 404 NotFound error.
When I added following dependencies, I retrieve the proxy javascript file clearly from expecting URL. Like URL:1111/singlar/hubs
Microsoft.Owin
Microsoft.Owin.Core
Microsoft.Owin.Host.SystemWeb
Microsoft.Owin.Security
Owin
Hope the answer helps someone.
In my startup.cs I changed the order from
app.UseWebApi(configuration);
app.MapSignalR();
to
app.MapSignalR();
app.UseWebApi(configuration);
And that fixed the issue.
It was working fine on localhost but the problem was that I have a custom global message handler that I'm using to display custom 404 messages on prod.
WebApiConfig.cs
config.MessageHandlers.Add( new WebApiCustomMessageHandler() );
public class WebApiCustomMessageHandler : DelegatingHandler
{
protected override async Task<HttpResponseMessage> SendAsync(
HttpRequestMessage request, CancellationToken cancellationToken )
{
HttpResponseMessage response = await base.SendAsync( request, cancellationToken );
//...
//... custom 404 handling
//...
return response;
}
}
I was getting 404 for all requests to .../signalr
Fixing the order in startup.cs fixed the 404 issue in the global message handler.
What worked for me was that in the App_Start I created a new item and selected the OWIN Startup class.
Then I modified it to look like this: Adding the app.MapSignalR();
public class Startup1
{
public void Configuration(IAppBuilder app)
{
app.MapSignalR();
}
}
With This in the HTML
<script src="~/signalr/hubs"></script>

Custom VirtualPathProvider not being used in IIS6

I added the following lines to Application_Start method in global.asax:
var provider = new TestVirtualPathProvider();
HostingEnvironment.RegisterVirtualPathProvider(provider);
Yet the 'TestVirtualPathProvider' is never used when deploying this application in IIS6 (it does in the ASP.NET Development Server).
Edit: the default path provider has always done its job correctly and served (non-embedded) views correctly. The problem is simply that I want to use my own path provider to provide embedded views. So, initially, I already had the following wildcard mapping configured:
Any possible reasons why this does not work in IIS6?
Are there any other factors (handlers for example) wich might influence the used VirtualPathProvider?
UPDATE: the fact that you want to handle extension-less URL's is an important point that's not mentioned in the question. Please see this page for help in setting up MVC with IIS 6: http://haacked.com/archive/2008/11/26/asp.net-mvc-on-iis-6-walkthrough.aspx. This should cover your scenario as well.
Most likely the same issue that I answered in this thread: http://forums.asp.net/t/995633.aspx
Basically, add this in your web.config:
<httpHandlers>
<add path="*" verb="GET,HEAD,POST" type="System.Web.StaticFileHandler" validate="true" />
</httpHandlers>
That other thread has some details that explain why this is necessary.
For the combination Custom VPP + IIS6 + Precompiled site, we need to add the VPP from AppInitailize();
public static class AppStart
{
public static void AppInitialize()
{
// code to be executed automatically by the framework
}
}
See also:
http://sunali.com/2008/01/09/virtualpathprovider-in-precompiled-web-sites/
I believe that you need to use an ISAPI filter in IIS6 to intercept URLs without extensions. Problem is that ISAPI will need to be done in c/c++.
IIS6 is configured to allow only certain extensions to be processed by the ASP.net pipeline.
To findout how you can redirct requests check out the post by DocV.

How do you modify the web.config appSettings at runtime?

I am confused on how to modify the web.config appSettings values at runtime. For example, I have this appSettings section:
<appSettings>
<add key="productspagedesc" value="TODO: Edit this default message" />
<add key="servicespagedesc" value="TODO: Edit this default message" />
<add key="contactspagedesc" value="TODO: Edit this default message" />
<add key="aboutpagedesc" value="TODO: Edit this default message" />
<add key="homepagedesc" value="TODO: Edit this default message" />
</appSettings>
Let's say, I want to modify the "homepagedesc" key at runtime. I tried ConfigurationManager and WebConfigurationManager static classes, but the settings are "read-only". How do I modify appSettings values at runtime?
UPDATE:
Ok, so here I am 5 years later. I would like to point out that experience has told me, we should not put any configuration that intentionally is editable at runtime in the web.config file but instead we should put it in a separate XML file as what one of the users commented below. This will not require any of edit of web.config file to restart the App which will result with angry users calling you.
You need to use WebConfigurationManager.OpenWebConfiguration():
For Example:
Dim myConfiguration As Configuration = System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration("~")
myConfiguration.ConnectionStrings.ConnectionStrings("myDatabaseName").ConnectionString = txtConnectionString.Text
myConfiguration.AppSettings.Settings.Item("myKey").Value = txtmyKey.Text
myConfiguration.Save()
I think you might also need to set AllowLocation in machine.config. This is a boolean value that indicates whether individual pages can be configured using the element. If the "allowLocation" is false, it cannot be configured in individual elements.
Finally, it makes a difference if you run your application in IIS and run your test sample from Visual Studio. The ASP.NET process identity is the IIS account, ASPNET or NETWORK SERVICES (depending on IIS version).
Might need to grant ASPNET or NETWORK SERVICES Modify access on the folder where web.config resides.
Changing the web.config generally causes an application restart.
If you really need your application to edit its own settings, then you should consider a different approach such as databasing the settings or creating an xml file with the editable settings.
And if you want to avoid the restart of the application, you can move out the appSettings section:
<appSettings configSource="Config\appSettings.config"/>
to a separate file. And in combination with ConfigurationSaveMode.Minimal
var config = System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration("~");
config.Save(ConfigurationSaveMode.Minimal);
you can continue to use the appSettings section as the store for various settings without causing application restarts and without the need to use a file with a different format than the normal appSettings section.
2012
This is a better solution for this scenario (tested With Visual Studio 2008):
Configuration config = WebConfigurationManager.OpenWebConfiguration(HttpContext.Current.Request.ApplicationPath);
config.AppSettings.Settings.Remove("MyVariable");
config.AppSettings.Settings.Add("MyVariable", "MyValue");
config.Save();
Update 2018 =>
Tested in vs 2015 - Asp.net MVC5
var config = System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration("~");
config.AppSettings.Settings["MyVariable"].Value = "MyValue";
config.Save();
if u need to checking element exist, use this code:
var config = System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration("~");
if (config.AppSettings.Settings["MyVariable"] != null)
{
config.AppSettings.Settings["MyVariable"].Value = "MyValue";
}
else { config.AppSettings.Settings.Add("MyVariable", "MyValue"); }
config.Save();
I know this question is old, but I wanted to post an answer based on the current state of affairs in the ASP.NET\IIS world combined with my real world experience.
I recently spearheaded a project at my company where I wanted to consolidate and manage all of the appSettings & connectionStrings settings in our web.config files in one central place. I wanted to pursue an approach where our config settings were stored in ZooKeeper due to that projects maturity & stability. Not to mention that fact that ZooKeeper is by design a configuration & cluster managing application.
The project goals were very simple;
get ASP.NET to communicate with ZooKeeper
in Global.asax, Application_Start - pull web.config settings from ZooKeeper.
Upon getting passed the technical piece of getting ASP.NET to talk to ZooKeeper, I quickly found and hit a wall with the following code;
ConfigurationManager.AppSettings.Add(key_name, data_value)
That statement made the most logical sense since I wanted to ADD new settings to the appSettings collection. However, as the original poster (and many others) mentioned, this code call returns an Error stating that the collection is Read-Only.
After doing a bit of research and seeing all the different crazy ways people worked around this problem, I was very discouraged. Instead of giving up or settling for what appeared to be a less than ideal scenario, I decided to dig in and see if I was missing something.
With a little trial and error, I found the following code would do exactly what I wanted;
ConfigurationManager.AppSettings.Set(key_name, data_value)
Using this line of code, I am now able to load all 85 appSettings keys from ZooKeeper in my Application_Start.
In regards to general statements about changes to web.config triggering IIS recycles, I edited the following appPool settings to monitor the situation behind the scenes;
appPool-->Advanced Settings-->Recycling-->Disable Recycling for Configuration Changes = False
appPool-->Advanced Settings-->Recycling-->Generate Recycle Event Log Entry-->[For Each Setting] = True
With that combination of settings, if this process were to cause an appPool recycle, an Event Log entry should have be recorded, which it was not.
This leads me to conclude that it is possible, and indeed safe, to load an applications settings from a centralized storage medium.
I should mention that I am using IIS7.5 on Windows 7. The code will be getting deployed to IIS8 on Win2012. Should anything regarding this answer change, I will update this answer accordingly.
Who likes directly to the point,
In your Config
<appSettings>
<add key="Conf_id" value="71" />
</appSettings>
in your code(c#)
///SET
ConfigurationManager.AppSettings.Set("Conf_id", "whateveryourvalue");
///GET
string conf = ConfigurationManager.AppSettings.Get("Conf_id").ToString();
Try This:
using System;
using System.Configuration;
using System.Web.Configuration;
namespace SampleApplication.WebConfig
{
public partial class webConfigFile : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
//Helps to open the Root level web.config file.
Configuration webConfigApp = WebConfigurationManager.OpenWebConfiguration("~");
//Modifying the AppKey from AppValue to AppValue1
webConfigApp.AppSettings.Settings["ConnectionString"].Value = "ConnectionString";
//Save the Modified settings of AppSettings.
webConfigApp.Save();
}
}
}

Resources