Thursday 31 July 2014

search textbox with image in asp.net

search textbox with image in asp.net

Remove .aspx from url in asp.net

Remove or hide .aspx from url in asp.net


In this article I will explain how to remove or hide .aspx from URL in asp.net. Remove or hide .HTML from url in asp.net OR Remove or hide .HTM from url in asp.net. if you want to remove or hide .aspx extension from url in asp.net then
you need to use  URL routing concept in asp.net.

but if you don't want to use URL routing in your code then you can use following code.

The main purpose of this task is make URL as SEO friendly.

Remove html or htm from url using code.

Other Articles - Step by step solution


=> Add Global.asax file in your website or project

=> And add following code in your global.asax file


void Application_BeginRequest(object sender, EventArgs e)
{
    String WebsiteURL = Request.Url.ToString();
    String[] SplitedURL = WebsiteURL.Split('/');
    String[] Temp = SplitedURL[SplitedURL.Length - 1].Split('.');

    // This is for aspx page
    if (!WebsiteURL.Contains(".aspx") && Temp.Length == 1)
    {
        if (!string.IsNullOrEmpty(Temp[0].Trim()))
            Context.RewritePath(Temp[0] + ".aspx");
    }
    /* // This is for HTML page
    if (!WebsiteURL.Contains(".html") && Temp.Length == 1)
    {
        if (!string.IsNullOrEmpty(Temp[0].Trim()))
            Context.RewritePath(Temp[0] + ".html");
    }
    // This is for HTM page
    if (!WebsiteURL.Contains(".htm") && Temp.Length == 1)
    {
        if (!string.IsNullOrEmpty(Temp[0].Trim()))
            Context.RewritePath(Temp[0] + ".htm");
    }*/
 }


=> Copy following div tag in your .aspx page , here you have to use page name only without .aspx extension



<div>
    Remove .aspx from asp.net website
    <a href="Default">Click</a>
    <%--Here write only page name without extension --%>
</div>


=> You can also redirect page without extension


protected void Page_Load(object sender, EventArgs e)
{
        Response.Redirect("Default");
}
 

connectionstring in asp.net



<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<connectionStrings>
  
<add  name="cn"
  connectionString="Server=0.0.0.0;
                    Database=db;
                    user=sa;
                    Password=db123"
  providerName="System.Data.SqlClient"/>

                  <!--Server IP Address
                      DatabaseName
                      Database User
                      Database User's Password-->
<add  name="cn"
  connectionString="ADMIN\SQLEXPRESS;
                    Database=db;
                    user=sa;
                    Password=db123"
  providerName="System.Data.SqlClient"/>

                    <!--Your Computer Name
                      DatabaseName
                      Database User
                      Database User's Password-->
</connectionStrings>
</configuration>



using System.Data;
using System.Data.SqlClient;
using System.Configuration;



SqlConnection cn;

cn1 = new SqlConnection(ConfigurationManager.ConnectionStrings["cn"].ConnectionString);

in asp.net


read xml file in c#

read xml file in c#



//Your xml file structure like following

<MyRootNodes>
  <MyRootNode Data0="0">
    <Data1>11</Data1>
    <Data2>22</Data2>
    <Data3>33</Data3>
    <Data4>44</Data4>
    <Data5>55</Data5>
  </MyRootNode>
  <MyRootNode Data0="00">
    <Data1>1111</Data1>
    <Data2>2222</Data2>
    <Data3>3333</Data3>
    <Data4>4444</Data4>
    <Data5>5555</Data5>
  </MyRootNode>
  <MyRootNode Data0="000">
    <Data1>111</Data1>
    <Data2>222</Data2>
    <Data3>333</Data3>
    <Data4>444</Data4>
    <Data5>555</Data5>
  </MyRootNode>
</MyRootNodes>



Add Namespace

using System.Xml;


Copy following method in your code behind file


    public void ReadXmlFile()
    {
    string Path = " ";// Set path local or server
    XmlDocument MyDoc = new XmlDocument();
    MyDoc.Load(Path);
    XmlElement RootElement = MyDoc.DocumentElement;
    XmlNodeList AllNondes = RootElement.SelectNodes("//MyRootNodes");

    for (int i = AllNondes.Count - 1; i >= 0; i--)
    {
        XmlNode Node = AllNondes[i];

        XmlNodeList NodeList = AllNondes[i].SelectNodes("//MyRootNode");
        for (int k = NodeList.Count - 1; k >= 0; k--)
        {
            XmlNode ChildNode = NodeList[k];
            string Name = ChildNode.Attributes[0].Value;

            decimal Data1 = Convert.ToDecimal(ChildNode["Data1"].InnerText);
            decimal Data2 = Convert.ToDecimal(ChildNode["Data2"].InnerText);
            decimal Data3 = Convert.ToDecimal(ChildNode["Data3"].InnerText);
            decimal Data4 = Convert.ToDecimal(ChildNode["Data4"].InnerText);
            decimal Data5 = Convert.ToDecimal(ChildNode["Data5"].InnerText);

            //Here all data in your xml file get Data1,Data2 ..... Variable
        }
    }
    }
 


Asp.net tutorials