How to access rewritten url from Salesforce Site - url-rewriting

I am using the Salesforce Sites URL rewriting feature, and need to retrieve the 'friendly' URL from the browser bar for some other processing. Is there any way I can retrieve this from within either one of the sites pages (so I can pass into a component as an attribute) or from a component controller directly?
To explain further, I am seeing a url in browser presently of 'site.force.com/examplesite/amazingpage' but if I try to retrieve $CurrentPage.url to pass into a component, or use Url.getCurrentRequestUrl() from within a component controller the result is a typical salesforce url ie. 'site.force.com/vfpage?id=123456789'.
Any suggestions most appreciated.
Cheers,
CH

Sorted.
Was obvious in the end - just added an additional method to the url rewriter class that allowed me to pass in a single url for rewriting, rather than trying to retrieve the re-written url from the view.
Cheers,
CH

Related

Redirect two pages back with url()->previous() in laravel

I'm creating an affiliate tracking system with some custom affiliate links. These links trigger a controller function to store some metrics in the database then redirect to the actual page the user intended.
My desired function is this: insert affiliate link into webpage->user clicks->controller fires/data stored->redirect to intended page. One of the pieces of data I want to store is the originating site the user clicked on the link. But because I'm calling the controller with a URL, url()->previous() gets my affiliate link that fired the controller instead of the originating site that has the link embedded.
I'm not sure if "previous()" can accept parameters but i tried "previous(2)" and that obviously didn't work.
$url = url()->previous();
$click->came_from = $url;
Using the code above, if my link was hosted on www.w3schools.com and my affiliate link is myurl/affiliatelink/2, I would want "www.w3schools.com" to be inserted into my database, but i'm getting "myurl/affiliatelink/2" inserted instead. Can anyone help me figure out a way around this?
The previous() method returns the user's last location within the app, not the last URL the browser accessed.
To do that, in Laravel, you can try Request::server('HTTP_REFERER'), or in plain PHP, $_SERVER['HTTP_REFERER'].
That said, be aware that HTTP_REFERER is not exactly the most reliable value. It can be spoofed (faked) easily or not provided at all, so test accordingly.
If possible, the best option would be to add a GET parameter to the link present in the remote site, so that when you receive the request in your Controller, you have the means to identify where the user is coming from.
You can simply get and store the previous url with the parameter in a variable($url) from your blade file, then pass the variable to your anchor tag as shown below:
#php
$url= url()->previous();
#endphp
href="{{url($url)}}"
This works very fine.

Pre-populate Ember DS.Store via ajax

Reading the Ember guide about the data store it's not clear how you pre-populate the store with your data. I see you can set up the RESTadapter with the host name, and the 'store.find' method will trigger a 'get' request if the data is not cached, but how can I initialize a DS.Store with JSON data via ajax before ever doing a find?
Ember guide model HTTP
The context for this is, a single page app that on page load gets a blob of json, which is used to model out the rest of the site. The end result gives the illusion that the site contains multiple pages.
Sounds like you want this.store.pushPayload(..)
http://emberjs.com/api/data/classes/DS.Store.html#method_pushPayload
Note that you only have access to the store inside Routes and Controllers. Consider putting this inside the activate hook of App.ApplicationRoute
http://emberjs.com/guides/routing/defining-your-routes/#toc_initial-routes
http://emberjs.com/api/classes/Ember.Route.html#method_activate

MVC3 Reverse Routing

I'm working on a project converting older .aspx pages to newer MVC pages. I'm currently using the routing function to map the existing legacy pages to use the newer MVC pages behind the scenes. This is working great because it is preserving the existing URL, however, whenever the controller needs to redirect the user OR an MVC Url.Action link is used, the URL it sends the user to is the MVC url and not the routed legacy page url. I realize that this is how its suppose to be functioning out of the box but I was wondering if MVC has "reverse routing" functionality of some sort. By reverse routing I am looking for something that allows the Url.Action("action") to return the routed .aspx associated url with the specified action instead of the default /controller/action link.
So for instance,
here is a sample route
context.MapRoute("AboutUs", "pages/aboutus.aspx", new { controller = "default", action = "aboutus" });
This enables domain.com/pages/aboutus.aspx to run the new MVC action "aboutus" from the DefaultController behind the scenes perfectly.
However, if on another MVC page I have a link created by
Url.Action("aboutus")
it points them to domain.com/mvc/aboutus. I would like it to point them to domain.com/pages/aboutus.aspx to keep uniformity across the site.
Thanks for any insights that you can provide. I might end up having to override the Url.Action method to look up the route and return the mapped url but I just wanted to check for existing functionality so I don't reinvent the wheel.
Try using the RouteUrl extension method, which matches the route by route name rather than route parameters, like so:
Url.RouteUrl("aboutus") // route name
MSDN: http://msdn.microsoft.com/en-us/library/dd460347

MVC sitemap provider

In mvc sitemap provider I want to show a list menu's based on the id of the logged in user.I was thinnking about dynamicnodeprovider but it is working for the first request it self that is before logging in.How can i achieve this?
Thanks,
Ajai
You could use cookies to achieve that. Set a cookie when the user logs in and read it when he comes back. Obviously this wouldn't work if:
the user blocks cookies
the user visits the site for the very first time
so you would need a default view for first visits; i don't think you can avoid this problem.
You could take the approach of making a JQuery AJAX call to a controller method which returns the required sitemap information. This enables you to update the sitemap whenever you like based on client side events.
e.g. see this post : http://joelabrahamsson.com/entry/xml-sitemap-with-aspnet-mvc
Another decision is if you want the controller to return the sitemap as ready generated HTML and dynamically replace it in the DOM. Or ( more work ) return the pure sitemap in XML and have JQuery generate the SiteMap markup for you.

How do you convert a form with method="get" to a mod_rewrite url?

I have a PHP MVC Web App and Apache mod_rewrite rules already working fine, but when I create forms using method="get", the submitted URL looks like
contact/submit?a=b&c=d
I would like my form to submit to
contact/submit/a/b/c/d
Both posting and getting the form work fine on the server side, but when using post method, the back button always asks for reposting the form values and furthermore I want the strings in the URL for SEO. I think JQuery might let me intercept the form submit event and refresh to the url dynamically, but it it seems there must be an easier way to do it that I am missing.
You could use the POST->REDIRECT->GET pattern that Spring Web Flow utilizes. This would allow you to post as you wish and then redirect to contact/submit/a/b/c/d. It would also solve the problem with the back button asking you if you want to resubmit your form data. See this related article.
The GET method uses standard query string arguments to pass form data via an HTTP GET request.
The HTTP GET request is not intended to modify any data on the server. POST is designed for modifying data on the server.
GET may be cached. POST will not.
/a/b/c/d is not a standard format (as in RFC) for passing data. However, for requesting data or URLs to post to, that has become popular.
So, if you are updating server data, just use a POST -> REDIRECT -> /a/b/c/d.
If you are just reading data from the server, then you will need to use a bit of Javascript to read your form values and construct a query string, and then go to it with window.location = ...
Have fun!

Resources