0

There is a URL. http://website.com/ap/mob/en#contactus. I want to catch the full URL including #contactus. I have tried to catch the URL from Page_load event with Request.Url.AbsoluteUri but my purpose is not getting solved. Can anyone help me in this regard?

3 Answers3

0

It is not possible, since the browser does not send the hash part to the server. There are workarounds involving JavaScript, of course, but those open up your application to script injection.

Here's what Wikipedia says:

The fragment identifier functions differently than the rest of the URI: namely, its processing is exclusively client-side with no participation from the web server — of course the server typically helps to determine the MIME type, and the MIME type determines the processing of fragments. When an agent (such as a Web browser) requests a web resource from a Web server, the agent sends the URI to the server, but does not send the fragment. Instead, the agent waits for the server to send the resource, and then the agent processes the resource according to the document type and fragment value.

Community
  • 1
  • 1
BCdotWEB
  • 1,009
  • 1
  • 14
  • 35
0

'#' in the Url is generally used to take user to the different section of the same page. The request will not go to server if url includes '#'.

Can you provide more detail on the scenario you have?

Prakash
  • 789
  • 6
  • 9
0

you can use javascript to get the full link then pass it to the code behind

<script language="javascript" type="text/javascript">

    function JavaScriptFunction() {
        document.getElementById('<%= hdnResultValue.ClientID %>').value = document.URL;
    }

</script>

<asp:HiddenField ID="hdnResultValue" Value="0" runat="server" />
        <asp:Button ID="Button_Get" runat="server" Text="run" OnClick="Button_Get_Click" OnClientClick="JavaScriptFunction();" />

then from the code behind get the value of hiddenfield which contains the current full URL

    protected void Button_Get_Click(object sender, EventArgs e)
    {
        string fullURL = hdnResultValue.Value;
    }
Ahmed Mandour
  • 330
  • 1
  • 8