locked
Can someone tell me what it takes to get this line to write out? RRS feed

  • Question

  • User-985624828 posted

    I am trying to detect the HTTP_REFERER for a call from my mobile website to my full website (it doesn't have "mobi" in it).  A user on another forum suggested this:

    <%
    Response.Write("HTTP_REFERFER value is :" + Request["HTTP_REFERER"]);
    %>

    But I can't get it to work with an ASPX page.  If I try it verbatim:

    <!DOCTYPE html>
    <html>
    <body>
    <%

    Response.Write("HTTP_REFERFER value is :" + Request["HTTP_REFERER"]);

    %>
    </body>
    </html>

    I get: Compiler Error Message: BC30452: Operator '+' is not defined for types 'String' and 'System.Web.HttpRequest'.

    If I change it to

    Response.Write(Request["HTTP_REFERER"]);

     I get Compiler Error Message: BC30203: Identifier expected.

    Can someone show me how to construct a minimalist page that will let me see the value of HTTP_REFERER?

    Sunday, September 16, 2018 5:50 PM

All replies

  • User409696431 posted

    I can't reproduce your error.

    <% Response.Write("HTTP_REFERFER value is :" + Request["HTTP_REFERER"]); %>

    works.

    Sunday, September 16, 2018 6:11 PM
  • User753101303 posted

    Hi,

    According to the compiler error number you are using VB rather than C#. Try maybe :

    Response.Write("HTTP_REFERER value is:" & Request("HTTP_REFERER"))

    or maybe (above is looking in QueryStrings, Forms, Cookies and ServerVariables) :

     Response.Write("HTTP_REFERER value is:" & Request.ServerVariables("HTTP_REFERER"))

    Sunday, September 16, 2018 7:46 PM
  • User-1716253493 posted

    use Request.UrlReferrer i.e Request.UrlReferrer.AbsolutePath

    https://docs.microsoft.com/en-us/dotnet/api/system.web.httprequest.urlreferrer?view=netframework-4.7.2

    Monday, September 17, 2018 1:46 AM
  • User-985624828 posted

    Could you please display the full text of your page and what extension it uses?  I'm using VBA and aspx.

    Monday, September 17, 2018 1:49 PM
  • User-985624828 posted

    That looks very promising, but it's in C# == can you translate it to VBA?

    Monday, September 17, 2018 1:57 PM
  • User-985624828 posted

    They both don't give a compile error and print out the string, but nothing for the HTTP_REFERER value..

    Monday, September 17, 2018 2:31 PM
  • User475983607 posted

    They both don't give a compile error and print out the string, but nothing for the HTTP_REFERER value..

    The HTTP_REFERER header is probably empty or does not exist.  

    This header is visible in the the browser's developer tools; F12.  All modern browsers have this feature.

    https://developers.google.com/web/tools/chrome-devtools/

    Monday, September 17, 2018 3:26 PM
  • User409696431 posted

    You won't have a referrer value if you just open the page.  You must link to it from another page to have a referrer.

    Monday, September 17, 2018 3:41 PM
  • User-985624828 posted

    I tried both of patriceSC's variants from a link.  Both of them trigger the error page on the web site I'm using for testing.

    Monday, September 17, 2018 5:51 PM
  • User-985624828 posted

    Thanks, but I'm trying to find out what the HTTP_REFERERER value is for a call from a mobile website to my full website.  I don't have the luxury of a full browser.

    Monday, September 17, 2018 5:54 PM
  • User475983607 posted

    artsnob

    Thanks, but I'm trying to find out what the HTTP_REFERERER value is for a call from a mobile website to my full website.  I don't have the luxury of a full browser.

    Something is not right... 

    First there is no guarantee that the  HTTP_REFERER header exists.  If you are not using a browser then it is unlikely the HTTP_REFERER exists as the header comes from the browser when the user clicks a link for example.

    The code shown generally points to VBScript not VBA.  If you are building a VBA application and interacting with a classic ASP application or Classic ASP interacting with an ASP,NET app, then explain the problem you are trying to solve in detail and why you need the HTTP_REFERER header.  

    Lastly, always include any errors.

    Monday, September 17, 2018 6:05 PM
  • User753101303 posted

    And which error do you have now ?

    Not directly related but it would be best to stop using Response.Write. Web Forms is intended to be used with controls (such as asp:Label etc...)

    Edit: you could maybe start with a single test page. When shown initially you have no referer. If you click a link that jjust direct to the same page you should have a referer (ie it tells from which page you are coming from).

    Note though that sending that is optional (and/or it could be likely easily spoofed). Avoid to use that as a safety measure. The original idea is likely to be able to track a navigation path if needed (and allowed by the user agent).

    Monday, September 17, 2018 6:16 PM
  • User-985624828 posted

    I can use both Edge and Chrome to access the mobile web site, but they're not full versions with devTools.  My long-running quest is to find a way that url rewrite on my IIS7 webserver can detect if a mobile call is coming FROM a link on my mobile website.  Is this detectable?  HTTP_REFERER would seem to offer the only hope for detection.  Is there any other way?

    Monday, September 17, 2018 7:33 PM
  • User475983607 posted

    I can use both Edge and Chrome to access the mobile web site, but they're not full versions with devTools.  My long-running quest is to find a way that url rewrite on my IIS7 webserver can detect if a mobile call is coming FROM a link on my mobile website.  Is this detectable?  HTTP_REFERER would seem to offer the only hope for detection.  Is there any other way?

    I don't understand the problem you are trying to solve or what it has to do with ASP.NET.

    If you have one site that has a link to another site under your control, add query string to the link.  Then just read the query string.

    Monday, September 17, 2018 8:00 PM
  • User-985624828 posted

    The mobile website I'm trying to customize has a "Full Website" option that doesn't permit anything other than the domain URL.  I think I see a simple workaround using some other options that do permit a full URL.  

    Still it WOULD be nice to see someone construct a page that would display the HTTP_REFERER of the link that accessed it.  It seems so elemental.  You'd think there'd be a what-is-my-ip type of web service.

    Tuesday, September 18, 2018 1:49 PM
  • User475983607 posted

    The mobile website I'm trying to customize has a "Full Website" option that doesn't permit anything other than the domain URL.  I think I see a simple workaround using some other options that do permit a full URL.  

    Still it WOULD be nice to see someone construct a page that would display the HTTP_REFERER of the link that accessed it.  It seems so elemental.  You'd think there'd be a what-is-my-ip type of web service.

    You must be working with some 3rd party service as what you're stating does not make sense.

    Remember the HTTP_REFERER is set by the browser when the user clicks a link or button.  It is up to the browser not a service.

    Tuesday, September 18, 2018 3:04 PM
  • User409696431 posted

    "Still it WOULD be nice to see someone construct a page that would display the HTTP_REFERER of the link that accessed it. It seems so elemental.  "

    It is elemental, and the code you've been given does that.   Assuming you use the correct code to match the page declaration (C# in a C# page, and VB.net in a VB page), and link to the page from another page in a browser, it works.  Just create the simple page in VS, create another page that links to it, and run it.

    If it's not working, in the scenario you are trying it in, you are not linking to the page using a browser that passes the HTTP_REFERER information.

    Tuesday, September 18, 2018 3:22 PM
  • User753101303 posted

    Not sure to get what you mean "doesn't permit anything other than the domain URL" ???

    The "referer" is the page from which you are coming from by following a a Href link. According to https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Referer it won't work if the referer uses https but your site uses http. Maybe this is your case ?

    Also there is no obligation to provide this information and it could be suppressed or forged. Which kind of decision will you take based on this decision ?

    Testing is as simple as having a web page showing this info and a link on the page you are already. Then when testing your page in VS/IIS Express you'll see no referer information as the browser is launched directly.

    If you click the link to the current page, the referer will show up as now you are on this page from a link that happens to be on the same page.

    You may want to explain what you are trying to do. It seems you are trying to workaround maybe this "doesn't permit anything other than the domain URL"  but I'm not sure how it could help and even what you mean. You are not trying to make a site showing mysite.com while the actual domain is somewhere.com ????

    Tuesday, September 18, 2018 5:06 PM