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?
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).
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.
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).
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!
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.
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).
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.
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).
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:
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.
:)
Thank you guys for the very helpfull answers.
We'll try them and let you know the results.
Best!
is working on a reply...