Sunday, September 12, 2010

ASP.NET web.config file

How to Create Database connection in the Web.config file

Connection string in asp.net c#. In Asp.net there is an easier way give the Connection String.We can add more than one Connection String in the web.config file.Then we can access these Connection Strings in any of our Pages.This is a simply superb concept in Asp.net.
For example,you have two connection strings one for your local server and another one for your live server.You simply add these two Connections in the web.config file and access the first connection in one page and in another page you can use the next connection.
ok, how to save this?
Well,Programming with C# is very easier when compared to other languages.give the coding below in your web.config file, in configuration section,
add the
<connectionStrings>
<add name="Conn" connectionstring="server=.;
database=Northwind;Integrated Security=True;"/>
</connectionStrings>
what is server?
may be the server is your localhost or your web server,if localhost means you just give the '.' or if your server is web server means just give the web server address 'XXX.XX.XXX'.
what is database?
database is the collection of data stored in a system.Its having a unique name.
what is Integrated Security?
if you are working in localhost means you dont need to give your userid and password.you just give the Integrated Security=True.
if you are using a webserver means the connection string will be slightly change,
<connectionStrings>
<add name="Conn" connectionstring="server=XXX.XXX.XX;
database=Northwind;uid=yourserveruserid;
pwd=yourserverpassword;/>
</connectionStrings>
 
what is uid and pwd?
uid is the userID when the sql installation you will give the userid and password.those userid and password will give here.
then,next step how to access this in our .aspx.cs file
add this namespace
using System.Data.Sqlclient
then add this in
 
SqlConnection con=new SqlConnection
(ConfigurationManager.ConnectionStrings["Conn"].
ConnectionString.ToString());
con.Open();  is used for connection opening
con.Close(); is used for connection closing.
 
This is the way of accessing the Connection Strings in all the pages.

How to manage Form authentication and the authorization in the Web.config file.

Authentication is necessary to almost every application. ASP.NET brings different Authentication Providers to make the authentication process easier. Among them, Forms-based authentication is the most often used one. With Forms Authentication, we create a login form with the logic to validate a user and .NET will create a Cookie on successful validation which the application will check for on each client request.
Forms Authentication is configured in web.config,
<configuration>

    <system.web>    

        <authentication mode="Forms"/>

    </system.web>

</configuration>
 
If we want to deny access to anonymous users, configure the Authorization section in the following manner,
 
<configuration>

    <system.web>

        <authentication mode="Forms"/>

        <authorization>

            <deny users="?" />

        </authorization>

    </system.web>

</configuration>
 
With Forms Authentication, we can configure the name of the cookie to use, the protection type, the URL to use for the loginUrl, the length of time(minutes) the cookie is in effect, and the path to use for the issued cookie. If no cookie name is specified, the default is .ASPXAUTH. The loginUrl is the location of the Login form and to which any unauthenticated requests for protected resources will be automatically redirected.
 
<configuration>

     <system.web>    

         <authentication mode= "Forms">

             < name="MyLoginCookie" loginUrl="MyLoginForm.aspx" protection="[All/None/Encryption/Validation]" timeout="30" path="/” />

         </authentication>

     </system.web>

 </configuration>
 
ASP.NET also allows us to define login credentials in the Web.config file and Authenticate against them using the Authenticate() method of the FormsAuthentication provider. Of course, we only consider this way if there is a relatively small number of users; or else we’d better authenticate a user against a database of user credentials.
<system.web>

    <authentication mode="Forms">

    <forms loginUrl="MyLoginPage.aspx">

        <credentials passwordFormat="[Clear/SHA1/MD5]">

            <user name="mary" password="msdyaredd" />

        </credentials>

    </forms>

    </authentication>

    </system.web>

</configuration>

How we should configure the Web,config file according to the E-mail sending...

After the <system.web/> we should change following changes to the Web.config file
<system.net> 
<mailSettings>
<smtp> 
<network
host="Host name"
port="25"
userName="Username"
password="password" /> 
</smtp>
</mailSettings> 
</system.net>

How to set the Image path when uploading images to the web..

<appSettings> <add key="ItemImagePath"
 value="Specify the path to save emages"/> </appSettings >
How to upload a larger size file into the web server...
additionally we have to configure the Web.config file as follows.
<httpRuntime executionTimeout="90" maxRequestLength="4096" 
useFullyQualifiedRedirectUrl="false" minFreeThreads="8"
 minLocalRequestFreeThreads="4" appRequestQueueLimit="100"/>

How to Fix a Slow Computer


Step 1:

To remove temporary files, look for the “temp” directory on the computer and empty all its contents. The directory can be found by clicking on “Documents and Settings”, “Administrator”, “Local Settings”, and then the “Temp” folder.

Step 2:

Look for the temporary Internet files and empty it from its contents. The temporary Internet files can be accessed by clicking on the “Control Panel” and then double clicking on the Internet options icon. The temporary Internet file and cookies contained in this folder must be removed.

Step 3:

Check for any registry and hard disk problems on the computer. For computers using the Windows 2000 and Windows XP Operating Systems, the user may check for hard disk errors as well as repair such discovered problems. To check and repair these hard disk errors, the user should right click the “C drive” and then click on “properties” followed by “tools”. Checking for errors is initiated upon clicking “Check now". The user may opt to check either or even both the file and the physical disk by selecting the areas requested to be checked. In advanced cases, the user may use a registry cleaner for analysis of the Windows registry.

Step 4:

Optimize the user’s Display settings by deleting needless visual options. This could be done by going to “Control Panel” then clicking on “System” and “Advanced” tab. A performance tab click settings will appear together with a wide range of options to choose from. Tick only the essential settings such as “Show shadows under menus”, “Show shadows under mouse pointer”, “Show translucent selection rectangle”, “Use drop shadows for icons labels on the desktop”, and “Use visual styles and buttons”.

Step 5:

Disable the computer’s file indexing service to reduce the usage of a large amount of the PC’s RAM. The file indexing can be disabled by double clicking “My Computer” icon and then right clicking the “C drive” and “properties”. Uncheck the option allowing indexing service and apply this modification to the C: subfolders as well as other files. Click on the “OK” icon to complete the process.

Step 6:

Disable the performance monitor utility provided by the Operating System by downloading and installing the Extensible Performance Counter List and then choosing every counter in the “Extensible performance counters” window. Remove the checkbox labeled as “performance counters enabled” to deactivate the performance counters.

Step 7:

Remove Desktop picture and minimize the number of fonts used.