ASP.NET Web.config file...

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

 

 

 

 

Published Wednesday, February 13, 2008 4:16 PM by Sahanr
Filed under:

Comments

# re: ASP.NET Web.config file...

Wednesday, February 13, 2008 10:07 AM by Mark Wisecarver

You should note Scott G. has some good tips on the Add, Clear and Remove commands and that most hosts may use localhost for the SMTP host setting.

# re: ASP.NET Web.config file...

Wednesday, May 21, 2008 7:38 AM by srinivas

can we change the path of the web.config file (we have one web.config file in root path can we move this file to a specified folder, if we can , could please explaine the process

# re: ASP.NET Web.config file...

Tuesday, July 29, 2008 4:29 AM by nguyen tri

In the section: "How to set the Image path when uploading images to the web..", I want to specify a relative path in Web folder (such as "|DataDirectory|\..."). How can I do with other directory (such as: root, bin, App_Browse,...).

# re: ASP.NET Web.config file...

Friday, February 27, 2009 9:42 AM by Mani

I this why we are using Xml to this all(such as data base connection,,)

# re: ASP.NET Web.config file...

Thursday, June 4, 2009 2:29 PM by drweb

Don't forget the defaultCredentials="false" to override using the user's info

# re: ASP.NET Web.config file...

Thursday, June 25, 2009 2:33 AM by Rama kishore

Hi..

I have hosted my application Godaddy shared hosting environment.Now i Want to upload images to my hosting server through my code.So i used file upload control to upload my files, when i am trying to upload file on to my web server every time it's prompting for user name password of my domain  .can any tell me how can i upload file on my shared hosting environment with out prompting authentication window.

Thanks in advance.

# re: ASP.NET Web.config file...

Monday, February 15, 2010 12:20 AM by GIRI BABU BHESETTI

Hi...

Thanks for giving good tips, regading web.config files, it is more usefull to me. I have small doubt in how to send mail through smtp using sql procedure.If u have plz tell me.

Thanks

# re: ASP.NET Web.config file...

Tuesday, October 12, 2010 6:37 AM by velu

It is usefull to me and i need an error handling procedure from this

# re: ASP.NET Web.config file...

Tuesday, October 12, 2010 6:42 AM by velmurugan

Hi,

This is usefull to me and I need an error handling procedure  for my practice if you have please show it

thanks.

# re: ASP.NET Web.config file...

Monday, November 15, 2010 8:19 AM by uttam24

What are the basic change should be done in web.config file while the files are uploaded into remote server.

# re: ASP.NET Web.config file...

Thursday, May 5, 2011 4:01 AM by sandesh

Thursday, June 25, 2009 2:33 AM by Rama kishore

Hi..

I have hosted my application Godaddy shared hosting environment.Now i Want to upload images to my hosting server through my code.So i used file upload control to upload my files, when i am trying to upload file on to my web server every time it's prompting for user name password of my domain  .can any tell me how can i upload file on my shared hosting environment with out prompting authentication window.

Thanks in advance.(sandesh@optimeservices.com)

# re: ASP.NET Web.config file...

Friday, June 10, 2011 1:31 AM by vidhya

it is useful to complete my assignment

# re: ASP.NET Web.config file...

Wednesday, July 27, 2011 6:48 AM by ekta Mall

How to call the string in code behind file.

# re: ASP.NET Web.config file...

Tuesday, October 4, 2011 5:18 AM by Dipeeka

Give more about mail sending

# re: ASP.NET Web.config file...

Wednesday, October 19, 2011 2:56 AM by akram

more info message displays saying

# re: ASP.NET Web.config file...

Wednesday, November 30, 2011 2:05 AM by SDM

Its really useful....

# re: ASP.NET Web.config file...

Wednesday, November 30, 2011 2:30 AM by SDM

public void fnSendMail(string strTo, string strSubject, string strBody, string strBMPpath, string strAttachment, string strCC)

       {

           System.Net.Mail.MailMessage mailMsg1 = new System.Net.Mail.MailMessage(ConfigurationManager.AppSettings["FromMail"].ToString(), strTo, strSubject, strBody);

           mailMsg1.IsBodyHtml = true;

           if (strCC != "")

           {

               mailMsg1.CC.Add(strCC);

           }

           if (strAttachment == "1")

           {

               System.Net.Mail.Attachment attachFile = new System.Net.Mail.Attachment(strBMPpath);

               mailMsg1.Attachments.Add(attachFile);

           }

           mailMsg1.Bcc.Add(ConfigurationManager.AppSettings["eMailBCC"].ToString());

           System.Net.Mail.SmtpClient client1 = new System.Net.Mail.SmtpClient(ConfigurationManager.AppSettings["SMTP"].ToString());

           System.Net.NetworkCredential SMTPUserInfo = new System.Net.NetworkCredential(ConfigurationManager.AppSettings["eMailUserName"].ToString(), ConfigurationManager.AppSettings["eMailPassword"].ToString());

           //client1.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network;

           client1.Credentials = SMTPUserInfo;

           client1.Send(mailMsg1);

       }

objMailer.fnSendMail(txtPerEmailid.Text, strSubject, strMessage, strBMPpath, strAttachment, strCC);

In web.config

<appSettings>

   <add key="FromMail" value=""/>

   <add key="eMailUserName" value=""/>

   <add key="eMailPassword" value=""/>

   <add key="eMailBCC" value=""/>

   <add key="SMTP" value=""/>

</appSettings>

# re: ASP.NET Web.config file...

Thursday, March 22, 2012 10:17 AM by tan

how many web config file per  application can have?

# re: ASP.NET Web.config file...

Wednesday, March 28, 2012 12:38 PM by Sahanr

Hi Tan -  Check this below link for more details.

forums.asp.net/.../1

# re: ASP.NET Web.config file...

Tuesday, April 10, 2012 5:06 AM by sachu

hi the above article really helped me. I need a help on how to configure a web app to change its datasource means the databases like SQlServer  to MSAccess or MySql by configuring Web.config and not changing the aspx files..

# re: ASP.NET Web.config file...

Wednesday, May 23, 2012 8:34 AM by Ravindra

Very Nice Article,Easy to understand

# re: ASP.NET Web.config file...

Thursday, May 31, 2012 10:28 AM by dharmendra

thanks..............

# re: ASP.NET Web.config file...

Wednesday, July 25, 2012 10:12 AM by Loftis

This web page is typically a walkthrough it can be the internet you wished about it and didnt

recognize who must. Glimpse here, and youll certainly discover it.

# re: ASP.NET Web.config file...

Tuesday, September 11, 2012 2:57 AM by Arun Icecreammmmmmmmmmm

ya, its workinggggggggggg

# re: ASP.NET Web.config file...

Friday, October 26, 2012 12:35 PM by VvlonUjMBLRG

bhitHS Great blog.Thanks Again. Great.

# re: ASP.NET Web.config file...

Sunday, November 4, 2012 4:14 AM by RbmelqENYzKEknuJz

PCoZA7 Looking forward to reading more. Great blog post.Thanks Again. Keep writing.

# re: ASP.NET Web.config file...

Friday, February 8, 2013 5:20 AM by Haugen

I lately stumbled on your website and also have been learning along.

I was thinking I might leave my very first remark.

I do not identify what to state except that I have liked reading through.

Solid website. I am going to maintain browsing this

site incredibly typically.

# re: ASP.NET Web.config file...

Wednesday, February 13, 2013 8:20 PM by Olmstead

I must show thanks to this writer just for bailing me from such a condition.

Right after checking throughout that the that the web and seeing solutions that were not helpful, I believed my entire

life was done. Existing devoid of the answers to that the difficulties you have fixed through your fine post is often a

critical case, as well as that the kind that could have in the wrong

line of attack damaged my career if I hadn’t encountered your blog.

Your primary talents and kindness in touching all the pieces

was very useful. I am not sure what I would have done if I hadn’t come across such a step just like this.

I’m able to at this time relish my future.

Thanks very much for this reliable and results-oriented help.

I will not think twice to recommend that the blog to anybody who desires guide about this area.