Skip to main content

How to get the URL of the current page using C#

I have often came across a question where developer look to ways to get different page URL

Below example will show you have to get different url and its segments

Let us say my page URL is 
http://localhost:51259/TEST.aspx?querystringOne=one

Below is code snippet to get different segments of URL 


Response.Write("<br/> 1= " + HttpContext.Current.Request.Url.Host);
Response.Write("<br/> 2= " + HttpContext.Current.Request.Url.Authority);
Response.Write("<br/> 3= " + HttpContext.Current.Request.Url.Port);
Response.Write("<br/> 4= " + HttpContext.Current.Request.Url.AbsolutePath);
Response.Write("<br/> 5= " + HttpContext.Current.Request.ApplicationPath);
Response.Write("<br/> 6= " + HttpContext.Current.Request.Url.AbsoluteUri);
Response.Write("<br/> 7= " + HttpContext.Current.Request.Url.PathAndQuery);

Result from above code is as 

1= localhost
2= localhost:51259
3= 51259
4= /TEST.aspx
5= /
6= http://localhost:51259/TEST.aspx?querystringOne=one
7= /TEST.aspx?querystringOne=one 


Comments

Popular posts from this blog

How to unblock your website on Facebook within 24 hours - unblock Facebook share

We recently noticed that one of our website was blocked by Facebook and we where not able to share any post on facebook.com and every time we tried to post on Facebook we used to get this message After reading tones of post and Facebook Help Centre, it was not very clear what caused this block our website which is related to company didn't violate any Community Standards. So our guess was that somebody maliciously reported our website as spam which resulted in block or it was false positive on Facebook side. How did we resolve it & action taken from our side. Step1 (didnt work) : First thing we did was to report it to Facebook using the link "Let us Know" which showed on error message when sharing any post from our website. This was not of much help as Facebook doesn't reply quickly or at all based on the feedback i got from forums, blogs & Facebook forums it self. Step 1 could work if Facebook can't get back & resolve the issue as false

Japanese new era date - 日本の新時代の日付

Since April 1, 2019, the new era name was announced for Japanese date Reiwa (令和). I came across few question by programmers regarding Japanese date and most of it was showing old era as not all user had updated their operating systems libraries. On April 25, Microsoft released packages for different Windows operating systems containing the updated registry key with the new era name. Update your device and check your registry to see if it has the new key, and then test your application. The Japanese calendar is divided into eras, and for most of the modern age of computing, system have been in the Heisei era; however, on May 1, 2019, a new era began Reiwa (令和). Because this is the first time in decades for an era to change, software that supports the Japanese calendar will need to be tested to ensure it will function properly when the new era begins. In the following sections, you will learn what you can do to prepare and test your application for the upcoming new era.

How to create Whatsapp Click To Chat link

WhatsApp now offers a feature called" Click To Chat " which allow recipient of email to initiate a chat with you with just click of  button or link So how to create a link or a button? WhatsApp now offer  " Click To Chat " feature which allows you to begin chat with someone without having having their number saved in contacts. This feature is very useful for marketing enthusiast. You can add a link with your WhatApp phone number in EDM / Newsletter so that user / recipients can get back to you with a click of a button or link. How do i add button / link to my EDM / Newsletter? You can do so by adding phone number & predefined message to following link https://api.whatsapp.com/send?phone=XXXXXXXXXX&text=My Message will go here You need to remember few thing while creating this link Add phone number without without Zero's 00 or Plus + to start of phone number You also need Encode message of you can encode complete URL   https:/