Pages

Showing posts with label web.config. Show all posts
Showing posts with label web.config. Show all posts

Saturday 20 June 2015

Code to set default startup page in web.config

Introduction:

When someone opens your website by entering your domain name in the web browser then by default it will show the startup page. If you haven't setup an startup page than it will look for Default.aspx or index.html page in the source files. You can setup your startup page in web.config file.

Code:

  <system.webServer>
    <directoryBrowse enabled="false"/>
    <defaultDocument>
      <files>
        <clear/>
        <add value="Default.aspx"/>
      </files>
    </defaultDocument>
  </system.webServer>

URL mapping in web.config

Introduction :
URL mapping is very useful tool to make your URL look good and meaningful to site user. It will overcome the querystring issue. The user sometimes got confused with the parameters passed in the url in the form of querystring.

Code :
For url mapping you have to pace this code in the web.config file in <system.web></system.web> tag

    <urlMappings enabled="true">
      <add url="~/ComputerCourse" mappedUrl="~/courses.aspx?cid=2"/>
      <add url="~/ComputerHardware" mappedUrl="~/courses.aspx?cid=3"/>
      <add url="~/MobileRepairing" mappedUrl="~/courses.aspx?cid=4"/>
      <add url="~/CuttingTailoring" mappedUrl="~/courses.aspx?cid=5"/>
      <add url="~/Beautician" mappedUrl="~/courses.aspx?cid=6"/>
    </urlMappings>


Sunday 14 June 2015

Connection String in Web.config

The web.config file stores the website configuration data, the connection string is used to store information on database connection.

The connection  string to connect to a local sql server database is :-

<connectionStrings>
    <add name="conn" connectionString="Data Source=.; Initial Catalog=DataBaseName; Integrated Security='True'" providerName="System.Data.SqlClient"/>
  </connectionStrings>

The connection string to connect to a server :-

<connectionStrings>
    <add name="conn" connectionString="Server=ServerAddress; Database=DatabaseName; User ID=userID; Password=password; Trusted_Connection=False" />
  </connectionStrings>