C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Reviews   Communities   Interview   Jobs   Projects   Training   Your Ad Here    
Silverlight Games | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Polls | Revenue Sharing | Lobby | Gift Shop |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...






Resources » Code Snippets » ASP.NET WebForms »

Getting URL without Query string


Posted Date: 26 Oct 2009    Resource Type: Code Snippets    Category: ASP.NET WebForms
Author: krishnavenikaladiMember Level: Gold    
Rating: 1 out of 5Points: 6




using System;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{ //creating string object for url wth querystring(for simplicity just i
//assigned the string value...
string uri1 = "http://www.dotnetspider.com/?id=120101&name=krishnavenikaladi";
//creating uriobject
Uri weburi = new Uri(uri1);
//querying uri object
string query = weburi.Query;
//returning url without querystring by using substring ()of immutable string class
string weburl = uri1.Substring(0, uri1.Length - query.Length);
Response.Write(weburl);
}
}




explanation
-->define an object 4 uri
---> query the uri object
--->using substring get required url






Responses

Author: Danasegarane.A    02 Nov 2009Member Level: Diamond   Points : 0
Request.Rawurl Will do the Trick


Author: Gaurav Arora    02 Nov 2009Member Level: Diamond   Points : 1
Good one!

Its a very good asnippet, I agree with Danasegarane.A


Author: krishnavenikaladi    02 Nov 2009Member Level: Gold   Points : 1
hi,
i do agree with u it can be done through request.rawurl.
here in my code snippet just i want to do in other way.....


Feedbacks      
Popular Tags   What are tags ?   Search Tags  
Sign In to add tags.
Using c#  .  URI  .  Substring  .  Remove quersyting from url  .  

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: Set Focus of a Control in ASP.NET
Previous Resource: Converting string to propercase
Return to Discussion Resource Index
Post New Resource
Category: ASP.NET WebForms


Post resources and earn money!
 
More Resources



dotNet Slackers

About Us    Contact Us    Privacy Policy    Terms Of Use