Accessing Web.Config from a separate solution - dll

I have two solutions, one is a class library and the other is a web application, and I want to get the connection string from the web.config file to the class library as I am developing a custom membership provider. I am using Framework 4.0 and MS Visual Studio 2010.
Thanks

You can put the configuration settings for any library in the main web.config. It's easy!
Connection strings are especially easy. Just add your connection string to the connectionstrings section with the same name it has in the library's app.config, and you're done!
<connectionStrings>
<add name="Sitefinity" connectionString="your connection string"/>
</connectionStrings>
To add configuration settings, at the top of your web config, find the applicationSettings section, and add your section's info. Note: be sure to set your library's settings access modifier to "Public". You can do this in the Properties ui.
<sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<section name="Your.Assembly" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</sectionGroup>
Then, add the section under applicationSettings.
<applicationSettings>
<Your.Assembly>
<setting name="TestSetting" serializeAs="String">
<value>a test value</value>
</setting>
</Your.Assembly>
</applicationSettings>

Related

Reading userSettings data from app.config file

Here is my app.config
<configuration>
<userSettings>
<MyProject.My.Settings>
<setting name="IP">
<value>127.0.0.1</value>
</setting>
</MyProject.My.Settings>
</uesrSettings>
</configuration>
I tried :
My.Settings.IP
and
TryCast(ConfigurationManager.GetSection("FormProcessing.Designer.My.MySettings"),My.MySettings)
I also tried many other ways and went through so many sites but still didn't get any way to work. I don't want to move it to as well.
This should work
<configuration>
<configSections>
<sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
<section name="MyProject.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" />
</sectionGroup>
</configSections>
<userSettings>
<MyProject.Properties.Settings>
<setting name="IP" serializeAs="String">
<value>127.0.0.1</value>
</setting>
</MyProject.Properties.Settings>
</userSettings>
</configuration>
Call it MyProject.Properties.Settings.Default.IP
However, the easiest way to create a Property should be, go to menu View / Solution Explorer. Navigate to [Your solution] / [Your project] / My Project / Settings.settings and double click Settings.settings. On the left panel go to Settings. Add a row Name IP, Type String, Scope User, Value 127.0.0.1. On the top there is an access Modifier, I will leave it as friend. Then just use [Your Project].Properties.Settings.Default.IP

Entity Framework, Custom Control, and No connection string named x, Still Runs

I recently rewrote a large program that my company uses to conduct business. I changed to Entity Framework early on. For the most part it has been working quite well.
One issue that has annoyed me for quite some time and now I have time to look into is, a custom control that pulls a question from the database causes a strange error.
When the custom control used SQL it would actually show the question on form display in the designer. At first this was pretty cool and I liked it. After switching it to use Entity Framework 6, when I load the form in the designer I get the error
No connection string named 'wotcDB' could be found in the application
config file.
It's totally in the app.config file. In fact the program has no problem compiling and running without issue. For the longest time I would just push Ignore and go to work on the form. The question of course no longer shows up in the designer.
The User Control is part of the application. The app.config file is there, and the program both runs and deploys fine. What's causing this?
Here is my app.config, ####### is sensitive data.
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</configSections>
<connectionStrings>
<add name="webDB" connectionString="metadata=res://*/Data.webDB.csdl|res://*/Data.webDB.ssdl|res://*/Data.webDB.msl;provider=MySql.Data.MySqlClient;provider connection string="user id=#######;password=#######;server=#######;database=#######;persistsecurityinfo=True""
providerName="System.Data.EntityClient" />
<add name="wotcDB" connectionString="metadata=res://*/Data.wotcDB.csdl|res://*/Data.wotcDB.ssdl|res://*/Data.wotcDB.msl;provider=System.Data.SqlClient;provider connection string="data source=#######;initial catalog=#######;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework""
providerName="System.Data.EntityClient" />
</connectionStrings>
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
<parameters>
<parameter value="mssqllocaldb" />
</parameters>
</defaultConnectionFactory>
<providers>
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
<provider invariantName="MySql.Data.MySqlClient" type="MySql.Data.MySqlClient.MySqlProviderServices, MySql.Data.Entity.EF6, Version=6.9.9.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d"></provider></providers>
</entityFramework>
<system.data>
<DbProviderFactories>
<remove invariant="MySql.Data.MySqlClient" />
<add name="MySQL Data Provider" invariant="MySql.Data.MySqlClient" description=".Net Framework Data Provider for MySQL" type="MySql.Data.MySqlClient.MySqlClientFactory, MySql.Data, Version=6.9.9.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d" />
</DbProviderFactories>
</system.data></configuration>
Rather than deal with the issue, since only I see it. I've found an answer at
This Stack Article
I put
If (System.ComponentModel.LicenseManager.UsageMode = System.ComponentModel.LicenseUsageMode.Designtime) Then
Load_Question()
End If
in the custom control load. I don't see the question during design time, which is fine for me. My other option was to put the connection string into the EF class, which is difficult to keep up since I'm using EF-Design and not code first.

ReportViewer 10 renders a blank screen when used in ASP.NET application

I have a .NET application written in VS 2010, target .NET version is 4.0, using the ReportingServices version 10 control. My SSRS server is SQL Server 2008 Enterprise. Web Server is IIS 7.5 on Windows Server 2008 R2 64-bit. I did review this question and answer but it did not resolve my problem.
The application has been working fine since August of last year until about a week ago. Of the five reports included in the application, three still work but two have stopped working. When the RS control appears on the screen, I get the message it is Loading with the twirly green circle. Eventually, that stops and all I have left is the control header without a report. I can see the parameters are properly populated and I can click on View Report but I never get the actual report on the screen.
I did go to the Report Manager (SSRS) site and verified the report works as expected. It does take about five minutes to generate, which the users are fine with. They understand it is chewing on a massive amount of data to generate the report. I can't do snapshots since they want the data real-time every time they run it.
I assume there is some sort of timeout, somewhere, but can't find it. One thing I did find is that the Loading message goes away before SQL Server has completed generating the result set for the report, which leads me to believe the timeout is in the application itself. Since other reporting applications on the same web server are working fine (different applications all part of the same web site), I'm not convinced the timeout is there. I did find a Timeout tag for the ServerReport section and set it to a ridiculously high value with no success. I have also re-published both report and application with no success. Code is included below. Thanks for your help in advance!
Relevant code in the .ASPX page:
<%# Register Assembly="Microsoft.ReportViewer.WebForms, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" Namespace="Microsoft.Reporting.WebForms" TagPrefix="rsweb" %>
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<rsweb:ReportViewer ID="ReportViewer" runat="server" Width="100%"
ProcessingMode="Remote" Font-Names="Arial" Font-Size="8pt"
ShowCredentialPrompts="False" SizeToReportContent="True" ShowParameterPrompts="true"
ShowRefreshButton="True" ShowFindControls="True" ShowPageNavigationControls="true" Height="500px">
<ServerReport DisplayName="Cluster Net Change" ReportPath="/Enrollment Reports/Cluster Net Change"
ReportServerUrl="http://reports.pinnacle.inside.pisd/reportserver" Timeout="6000000" />
</rsweb:ReportViewer>
Relevant sections in web.config:
<assemblies>
<add assembly="System.DirectoryServices.Protocols, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>
<add assembly="Microsoft.ReportViewer.Common, Version=10.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>
<add assembly="Microsoft.ReportViewer.WebForms, Version=10.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>
</assemblies>
<buildProviders>
<add extension=".rdlc" type="Microsoft.Reporting.RdlBuildProvider, Microsoft.ReportViewer.Common, Version=10.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>
</buildProviders>
<httpHandlers>
<add verb="*" path="Reserved.ReportViewerWebControl.axd" type="Microsoft.Reporting.WebForms.HttpHandler, Microsoft.ReportViewer.WebForms, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
</httpHandlers>
<handlers>
<add name="ReportViewerWebControlHandler" preCondition="integratedMode" verb="*" path="Reserved.ReportViewerWebControl.axd" type="Microsoft.Reporting.WebForms.HttpHandler, Microsoft.ReportViewer.WebForms, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
</handlers>

web.config applicationSettings values not being read from WCF service

I have a WCF service with a setting I created in the WCF application property editor (settings tab).
It has created something like the following property in MySettings class in the Settings.Designer.vb file. Notice the DefaultSettingValueAttribute is set to "This is the OLD value". That's my value for local testing.
<Global.System.Configuration.ApplicationScopedSettingAttribute(), _
Global.System.Diagnostics.DebuggerNonUserCodeAttribute(), _
Global.System.Configuration.DefaultSettingValueAttribute("This is the OLD value")> _
Public ReadOnly Property Information() As String
Get
Return CType(Me("Information"),String)
End Get
End Property
On the production server I have changed the web.config file as below. The "NEW" value would be useful for the production server. It represents a connection string, or production resource address.
<applicationSettings>
<setting name="Information" serializeAs="String">
<value>This is the NEW value</value>
</setting>
</applicationSettings>
The problem is after restarting the WCF service (rebooting the server machine completely), it never reads the new value. It continues to use the old value that was set as the default value in the designer file.
I think this must have to do with file permissions, but I don't see anything in the event log that indicates a problem. It's like the WCF service isn't even trying to read the web.config file. I don't find anything like this problem on Google and I've run out of search term ideas.
Why isn't the service reading the settings value from the web.config file?
Did you make sure to add the SectionGroup to the ConfigSections of the production web server?
It should look something like:
<sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
<section name="MyWCFService.My.MySettings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</sectionGroup>
and your application settings section should look something like:
<applicationSettings>
<MyWCFService.My.MySettings>
<setting name="Information" serializeAs="String">
<value>This is the NEW value</value>
</setting>
</MyWCFService.My.MySettings>
</applicationSettings>

IBindingConfigurationElement - How to implement and add to configuration?

I'm trying to extend WCF with a custom binding which has required that I replace message formatting, encoding and security elements within the WCF stack. To facilitate ease-of-use with this binding, I'd like to make it configurable from a configuration file in the same way as the built-in bindings (i.e. a named element, not customBinding).
The WCF standard bindings all inherit from StandardBindingElement, which in turn implements IBindingConfigurationElement. If I implement this interface or inherit from the class, how can I make the configuration element available to the WCF configuration system?
The post at http://blogs.msdn.com/b/carlosfigueira/archive/2011/07/26/wcf-extensibility-binding-and-binding-element-configuration-extensions.aspx talks about adding configuration extension for bindings and binding elements, you should find more information there.
I did some digging and found the bindingExtensions element on MSDN. Although the documentation there indicates that you can add bindings this way, I had a peek at my machine.config file and found the following 3.5 bindings registered there:
<bindingExtensions>
<add name="wsHttpContextBinding" type="System.ServiceModel.Configuration.WSHttpContextBindingCollectionElement, System.WorkflowServices, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
<add name="netTcpContextBinding" type="System.ServiceModel.Configuration.NetTcpContextBindingCollectionElement, System.WorkflowServices, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
<add name="webHttpBinding" type="System.ServiceModel.Configuration.WebHttpBindingCollectionElement, System.ServiceModel.Web, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
<add name="basicHttpContextBinding" type="System.ServiceModel.Configuration.BasicHttpContextBindingCollectionElement, System.WorkflowServices, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
</bindingExtensions>
These classes function as collections of binding elements, inheriting from the odd StandardBindingCollectionElement<TStandardBinding, TBindingConfiguration> class. This looks to be the correct class to inherit from and create an associated StandardBindingElement from.
The collection is registered using the syntax listed above and should then function exactly the same as built-in WCF bindings.