Follow by Email

Tuesday, 19 June 2012

What is Web.config in Asp.net ?


We should have good knowledge about the Web.config file, because it's a major character when we going to develop web applications using ASP.net. First, I like to give some examples "What we can do using the Web.config file"...And after I'll discuss how we going to code the examples.
  • Can create database connection using the Web.config file
  • According to the user log in system environment, we can modify the Authentication and Authorization.
  • We can set image path for the uploading images.
  • Also we can manage the lager size files, when uploading to the web server.
  • If the System.Net.Mail email sending, we should configure the Web.config file.
How to Create Database connection in the Web.config file
You can write following code before the <system.web> tag and inside the <Configuration> tag
<connectionStrings>
 <add name="NameConnectionString" connectionString="Data Source= (Default);Initial Catalog=DatabaseName;User ID=Username;Password="Your Password"" providerName="System.Data.SqlClient"/> </connectionStrings>
How to manage Form authentication and the authorization in the Web.config file.
Following code demonstrate the way it can be implement.
<authentication mode="Forms">
<forms loginUrl="login page url" timeout="30"></forms>
</authentication>

Then you should show the location which need to be restricted from anonymous users.
After the <system.web/> tag we can write following code to above purpose. It's pretty cool, isn't it..?

<location path="FolderNameAuthenticationNeed" allowOverride="true"> <system.web>
<authorization> <deny users="?"/>
</authorization> </system.web> </location>

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"/>

0 comments:

Post a Comment


                                                            

 
Design by Abhinav Ranjan Sinha