Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Vitor Milano 3 posts 23 karma points
    Jan 23, 2012 @ 15:31
    Vitor Milano
    0

    Request Origin

    Hy,

    We are just starting with Umbraco and have a funcional requirement at a solution that is to catch the user request  origin URL so we can do a specific action on the site flow.

    Is there any supported method on Umbraco to analyse that user request and get the URL?

    Thanks a lot.

    Best.

  • Rodion Novoselov 694 posts 859 karma points
    Jan 23, 2012 @ 16:43
    Rodion Novoselov
    0

    Hi. You can always access the original URL (the one that was before any URL rewriting) by the HttpRequest.RawUrl property (e.g. HttpContext.Current.Request.RawUrl).

  • Vitor Milano 3 posts 23 karma points
    Jan 23, 2012 @ 17:11
    Vitor Milano
    0

    Hi Rodion,

    Thanks for your feedback.

    But actually, I was refering to the HOST of the user. That way I can track back and know that some specific user came to my site using some link hosted at a partner hotsite.

    On .NET Framework, we would do something like:

    Uri uri = HttpContext.Current.Request.UrlReferrer; and then take the HOST from the URI object.

    Does anyone have done that on Umbraco?

    Thanks a lot.

  • Rodion Novoselov 694 posts 859 karma points
    Jan 23, 2012 @ 17:29
    Rodion Novoselov
    0

    You can get the host of the user simple querying standard server variables. Or even simpler by requesting either HttpRequest.UserHostName (if you want its DNS name) or HttpRequest.UserHostAddress (if you want the IP).

  • Tim 1193 posts 2675 karma points MVP 4x c-trib
    Jan 23, 2012 @ 17:31
    Tim
    0

    Hi Vitor,

    You could do that pretty easily. We have done it on a few Umbraco sites. We've just written a simple HttpModule that checks the HttpContext.Current.Request.UrlReferrer and if it's not from the current site, we store the referrer in a cookie for later use. But you could do whatever you wanted with the referrer once you've grabbed it (store it in the database for example). A very basic example of the code would be something like:

    using System;
    using System.Collections.Generic;
    using System.Text;
    using System.Web;
    
    namespace Example
    {
        class ExampleModule : IHttpModule
        {
            public ExampleModule()
            {
    
            }
    
            public String ModuleName
            {
                get { return "ExampleModule"; }
            }
    
            // hook into the application_beginrequest method to get referrer
            public void Init(HttpApplication application)
            {
                application.BeginRequest += (new EventHandler(this.Application_BeginRequest));
            }
    
            //function that calls the code we need
            private void Application_BeginRequest(Object source, EventArgs e)
            {
                //put your code here to get the referrer and do stuff with it
            }
    
            public void Dispose()
            {
    
            }
        }
    }

    Once you've compiled your module, you just need to register it in your web.config file (see here for details:  http://msdn.microsoft.com/en-us/library/ie/ms227673.aspx, scroll down to near the bottom for the relevant section). Once you've done that, all requests for pages on your site should get checked!

    Hope that helps.

    :)

  • Vitor Milano 3 posts 23 karma points
    Jan 23, 2012 @ 17:39
    Vitor Milano
    0

    Thank you guys for the very helpfull answers.

    We'll try them and let you know the results.

     

    Best!

Please Sign in or register to post replies

Write your reply to:

Draft