RE: security in windows app
- From: stcheng@xxxxxxxxxxxxxxxxxxxx (Steven Cheng[MSFT])
- Date: Thu, 18 Jan 2007 01:14:31 GMT
Thanks for the reply Gerhard,
If you use the certain ASP.NET 2.0 services in a non-ASP.NET application,
you should put the same configuration(include the connectionstringt) in the
application's App.config file. Here is the complete App.config I used in my
local test application(a winform app).
# the connectionstrings are always cofigured in the<connectionStrings>
section
=========app.config=============
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
</configSections>
<connectionStrings>
<add name="ProfileAppDB" connectionString="Data Source=localhost;Initial
Catalog=ProfileAppDB;Integrated Security=True"
providerName="System.Data.SqlClient" />
</connectionStrings>
<system.web>
<anonymousIdentification enabled="true"/>
<profile defaultProvider="NewAspNetSqlProfileProvider" >
<providers>
<add name="NewAspNetSqlProfileProvider"
connectionStringName="ProfileAppDB" applicationName="/"
type="System.Web.Profile.SqlProfileProvider, System.Web,
Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
</providers>
<properties >
<add name="string1" type="String" allowAnonymous="true"/>
<add name="string2" type="String" allowAnonymous="true"/>
</properties>
</profile>
<membership defaultProvider="NewAspNetSqlMembershipProvider">
<providers>
<add name="NewAspNetSqlMembershipProvider"
type="System.Web.Security.SqlMembershipProvider, System.Web,
Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
connectionStringName="ProfileAppDB" enablePasswordRetrieval="false"
enablePasswordReset="true" requiresQuestionAndAnswer="true"
applicationName="/" requiresUniqueEmail="false" passwordFormat="Hashed"
maxInvalidPasswordAttempts="5" minRequiredPasswordLength="7"
minRequiredNonalphanumericCharacters="1" passwordAttemptWindow="10"
passwordStrengthRegularExpression="" />
</providers>
</membership>
<roleManager defaultProvider="NewAspNetSqlRoleProvider" enabled="true">
<providers>
<add name="NewAspNetSqlRoleProvider" connectionStringName="ProfileAppDB"
applicationName="/"
type="System.Web.Security.SqlRoleProvider, System.Web, Version=2.0.0.0,
Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
</providers>
</roleManager>
</system.web>
</configuration>
====================================
As for reading connectionstring setting from code, you can consider the
following means:
1. Directly open your application's config file through XML api(such as
XmlDocument) and use SelectNodes(SelectSingleNode) to locate the
connectionstring element and read the value.
2. .NET 2.0 has provided built-in classes for accessing application's
configuration. If you want to programmatically read configuration setting
in the same application, you can use
"ConfigurationManager.ConnectionStrings" static property. If you want to
open another aplication's app.config and read setting, you can use
ConfigurationManager.OpenExeConfiguration method to open a specified
exe.config file. e.g.
==========
Configuration config =
ConfigurationManager.OpenExeConfiguration(@"d:\temp\app1\app1.exe.config");
string connstr =
config.ConnectionStrings.ConnectionStrings["sqlconnstr1"].ConnectionString;
===================
#ConfigurationManager Class
http://msdn2.microsoft.com/en-us/library/system.configuration.configurationm
anager.aspx
Hope this helps you further.
Sincerely,
Steven Cheng
Microsoft MSDN Online Support Lead
This posting is provided "AS IS" with no warranties, and confers no rights.
.
- Follow-Ups:
- RE: security in windows app
- From: Gerhard
- RE: security in windows app
- References:
- RE: security in windows app
- From: Steven Cheng[MSFT]
- RE: security in windows app
- From: Gerhard
- RE: security in windows app
- From: Steven Cheng[MSFT]
- RE: security in windows app
- Prev by Date: RE: Better security
- Next by Date: RE: Better security
- Previous by thread: RE: security in windows app
- Next by thread: RE: security in windows app
- Index(es):
Relevant Pages
|