page.aspx/variable in ASP.NET -


is possible pass/get variables page.aspx/value in asp.net? i'd have page website.com/folder/name instead of website.com/folder/?name , name value.

i've done similar routing allow dates passed through blog entries , stuff.

to setup need have page processing, lets call folder.aspx , add in route information global.ascx.cs file.

so lets @ routes ...

routes

routes need work specific , work there way out general. way request able find specific version applies url specified. following code needs added global.ascs.cs file.

    void application_start(object sender, eventargs e)     {         // code runs on application startup         setroutes(routetable.routes);     }      private static void setroutes(routecollection routes)     {          routes.mappageroute("folder-file",                             "{folder}/{file}",                             "~/folder.aspx");          routes.mappageroute("folder",                             "{folder}",                             "~/folder.aspx");     } 

one thing note might need sort out other routes in addition this intercept other sub folder references.

right, routes sorted can access route values in code behind of folder.aspx page.

page code behind

    protected void page_load(object sender, eventargs e)     {         var folder = page.routedata.values["folder"] string;         var file = page.routedata.values["file"] string;          lblfolder.text = string.isnullorempty(folder) ? "nothing" : folder;         lblfile.text = string.isnullorempty(file) ? "nothing" : file;     } 

the above code example how access route values, , i've assigned them labels checking null or empty :-)

so access folder.aspx page can browse domain/folder/name or domain/folder .

hope helps.


Comments

Popular posts from this blog

c++ - How do I get a multi line tooltip in MFC -

asp.net - In javascript how to find the height and width -

c# - DataTable to EnumerableRowCollection -