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

 

 

 

 

28 Comments

  • 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.

  • 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

  • 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,...).

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

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

  • 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.

  • 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

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

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

    thanks.

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

  • 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)

  • it is useful to complete my assignment

  • How to call the string in code behind file.

  • Give more about mail sending

  • more info message displays saying

  • Its really useful....

  • 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







  • how many web config file per application can have?

  • Hi Tan - &nbsp;Check this below link for more details.

    forums.asp.net/.../1

  • 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..

  • Very Nice Article,Easy to understand

  • thanks..............

  • 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.

  • ya, its workinggggggggggg

  • bhitHS Great blog.Thanks Again. Great.

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

  • 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.

  • 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.

Comments have been disabled for this content.