PDA

View Full Version : چگونگی تغییر در Web.conf از طریق صفحات وب



tc1000
دوشنبه 14 خرداد 1386, 14:18 عصر
با سلام
من نیاز دارم که بتونم یک سری اطلاعات رو از Web.conf تغییر بدم البته در صفحه وب
به طور مثال connectionString رو بتونم تغییر بدم
از استاتید خواهمشند است که بنده رو راهنمایی کنند

Behrouz_Rad
دوشنبه 14 خرداد 1386, 16:43 عصر
ASP.NET 2.0


Configuration objConfig = WebConfigurationManager.OpenWebConfiguration("~");
AppSettingsSection objConSettings = (AppSettingsSection)objConfig.GetSection("connectionStrings");
if (objConSettings != null)
{
objConSettings.Settings["conString"].Value = "Ye Chizi";
objConfig.Save();
}

rahele_sa
دوشنبه 11 تیر 1386, 18:13 عصر
AppSettingsSection objConSettings = (AppSettingsSection)objConfig.GetSection("connectionStrings");

از این خط خطا میگره



Unable to cast object of type 'System.Configuration.ConnectionStringsSection' to type 'System.Configuration.AppSettingsSection'.

rahele_sa
سه شنبه 12 تیر 1386, 09:08 صبح
چرا کسی جواب نمیده ؟

Behrouz_Rad
سه شنبه 12 تیر 1386, 14:26 عصر
توی Web.Config ات چی نوشتی؟

rahele_sa
چهارشنبه 13 تیر 1386, 09:40 صبح
<?xml version="1.0"?>
<!--
Note: As an alternative to hand editing this file you can use the
web admin tool to configure settings for your application. Use
the Website->Asp.Net Configuration option in Visual Studio.
A full list of settings and comments can be found in
machine.config.comments usually located in
\Windows\Microsoft.Net\Framework\v2.x\Config
-->
<configuration xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0">
<appSettings/>

<connectionStrings>
<add name="MyDB_DBConnectionString" connectionString="Data Source=RAHELE;Initial Catalog=MyDB;Persist Security Info=True;User ID=sa;Password=1" providerName="System.Data.SqlClient" />
</connectionStrings>

<system.web>
<customErrors mode="Off"/>
<!--
Set compilation debug="true" to insert debugging
symbols into the compiled page. Because this
affects performance, set this value to true only
during development.
-->
<compilation debug="true"/>
<!--
The <authentication> section enables configuration
of the security authentication mode used by
ASP.NET to identify an incoming user.
-->
<authentication mode="Windows"/>
<!--
The <customErrors> section enables configuration
of what to do if/when an unhandled error occurs
during the execution of a request. Specifically,
it enables developers to configure html error pages
to be displayed in place of a error stack trace.

<customErrors mode="RemoteOnly" defaultRedirect="GenericErrorPage.htm">
<error statusCode="403" redirect="NoAccess.htm" />
<error statusCode="404" redirect="FileNotFound.htm" />
</customErrors>
-->

</system.web>


</configuration>

rahele_sa
یک شنبه 17 تیر 1386, 14:37 عصر
چرا کسی جواب نمی ده ؟!!!

M-Gheibi
یک شنبه 17 تیر 1386, 17:18 عصر
<?xml version="1.0"?>
<!--
Note: As an alternative to hand editing this file you can use the
web admin tool to configure settings for your application. Use
the Website->Asp.Net Configuration option in Visual Studio.
A full list of settings and comments can be found in
machine.config.comments usually located in
\Windows\Microsoft.Net\Framework\v2.x\Config
-->
<configuration xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0">
<appSettings/>

<connectionStrings>
<add name="MyDB_DBConnectionString" connectionString="Data Source=RAHELE;Initial Catalog=MyDB;Persist Security Info=True;User ID=sa;Password=1" providerName="System.Data.SqlClient" />
</connectionStrings>

<system.web>
<customErrors mode="Off"/>
<!--
Set compilation debug="true" to insert debugging
symbols into the compiled page. Because this
affects performance, set this value to true only
during development.
-->
<compilation debug="true"/>
<!--
The <authentication> section enables configuration
of the security authentication mode used by
ASP.NET to identify an incoming user.
-->
<authentication mode="Windows"/>
<!--
The <customErrors> section enables configuration
of what to do if/when an unhandled error occurs
during the execution of a request. Specifically,
it enables developers to configure html error pages
to be displayed in place of a error stack trace.

<customErrors mode="RemoteOnly" defaultRedirect="GenericErrorPage.htm">
<error statusCode="403" redirect="NoAccess.htm" />
<error statusCode="404" redirect="FileNotFound.htm" />
</customErrors>
-->

</system.web>


</configuration>


با اجازه‌ی مدیر بخش :)


Configuration objConfig = WebConfigurationManager.OpenWebConfiguration("~");
ConnectionStringsSection objConSettings = (ConnectionStringsSection)objConfig.GetSection("connectionStrings");
if (objConSettings != null)
{
objConSettings.ConnectionStrings["MyDB_DBConnectionString"].ConnectionString = "......";
objConfig.Save();
}