Search code examples
asp.netwebmethod

how i can create a page that works like stackoverflow


i want to know how did these pages work! like this :

https://stackoverflow.com/questions/ask

there is no extension in end of the address!

is this a way to call webmethods directly?! i wrote this page , but i think its not right!

public partial class _Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
           string name= Request.QueryString["name"];
           if (Request.PathInfo == "/SayHi")Response.Write( SayHi(name));
        }

        [WebMethod]
        public static string SayHi(string name)
        {
            return "Hi " + name;
        }

        //[WebMethod]
        //public static string SayHi()
        //{
        //    return "Hi ";
        //}
    }

Solution

  • For ASP.NET, you can use ASP.NET Routing, which will allow you to separately configure what the URLs should look like.

    You can use it both for regular WebForms apps and with the newer ASP.NET MVC.