I am trying to implement the sitecore wildcard url routing in the sitecore 6.6 which is MVC based.
I am missing something due to which the url is not well formed.
Could you please help me achieve this if you have any idea.
http://d.local.mvcsitecore.com/Store/Browse/,-w-,Genre.aspx?Genre=Classical
This is the url that is formed.
I don't think your issue is related to routing but some custom LinkProvider instead. Check your code for an overridden instance of GetItemUrl method in Sitecore.Links.LinkProvider. You may need to post your code here for us to be able to help you further.
Is the target item selected for wildcard route you've created? You will also need to replace the tokens yourself, it won't happen automatically as far as I know.
var ts = WildcardManager.Provider.GetWildcardUrl(item, Sitecore.Context.Site);
var data = new NameValueCollection { { "%Token%", value } };
var url = ts.ReplaceTokens(data);
Related
I'm having a problem using parameters in Durandal for an ASP.NET MVC application...
I use MVC Route Attributes, for example:
[Route("admin/pages")], [Route("admin/blog")], etc..
And I integrate Durandal as follows:
main.js:
app.start().then(function() {
viewEngine.viewExtension = '/';
viewLocator.convertModuleIdToViewId = function (moduleId) {
return moduleId.replace('viewmodels', '');
};
app.setRoot('viewmodels/admin/shell', 'entrance');
});
This works nicely, as the viewId ends up matching the MVC route.
However, I now face a serious problem with trying to use parameters in the routes. For example, I have one route as follows:
[Route("admin/localization/localizable-strings/{languageId}")]
and my Durandal route for this is:
localization/localizable-strings/:languageId
Example anchor tag:
Localize
This doesn't work, as it seems Durandal doesn't pass the parameter to the server. It simply retrieves the HTML from /admin/localization/localizable-strings which returns a 404 page because no parameter was passed to the MVC action.
What are my options here?
I know this question is almost 2 years old now, but I obviously forgot to close it with my solution at the time. Basically, Brett and Marvin were correct, but since I was so new to Durandal (and SPAs in general) at the time, I misunderstood exactly what they were telling me. I ended up doing this:
self.cultureCode = null;
self.activate = function (cultureCode) {
self.cultureCode = cultureCode;
if (!self.cultureCode) {
self.cultureCode = null;
}
};
And the durandal route was set up as follows;
"localization/localizable-strings/:cultureCode"
I would then use that parameter to obtain the relevant data via ajax. My mistake was wanting the parameter to be able to be used in the MVC action method so that I could obtain some data server side, which of course doesn't work...
I'm using Symfony 1.4 and i want to forward in my controller to another controller and action with some parameters.
After creating a "bike" with "bike/create" i want to forward to "bike/show/id/X" with the id i got from my new bike instance.
$forwardString = 'bike/show/id/'.$bike->id;
$this->forward($url);
This does not work :-(
Maybe you can help! :)
Greetings!
The method definition for forward is public function forward($module, $action) the request should be preserved and if theese are things not currently in the request you will have to add them first.
Also you might even need redirect instead so the url changes and where you just give it the url public function redirect($url, $statusCode = 302) so usage would be $this->redirect('bike/show?id=' . $bike->id);
Recently, I'm trying to migrating my application from CakePHP to Grails. So far it's been a smooth sailing, everything I can do with CakePHP, I can do it with much less code in Grails. However, I have one question :
In CakePHP, there's an URL Prefix feature that enables you to give prefix to a certain action url, for example, if I have these actions in my controller :
PostController
admin_add
admin_edit
admin_delete
I can simply access it from the URL :
mysite/admin/post/add
mysite/admin/post/edit/1
mysite/admin/post/delete/2
instead of:
mysite/post/admin_add
mysite/post/admin_edit/1
mysite/post/admin_delete/2
Is there anyway to do this in Grails, or at least alternative of doing this?
Grails URL Mappings documentation doesn't help you in this particular case (amra, next time try it yourself and post an answer only if it's any help). Daniel's solution was close, but wouldn't work, because:
the action part must be in a closure when created dynamically
all named parameters excluding "controller", "action" and "id" are accessible via the params object
A solution could look like this:
"/admin/$controller/$adminAction?/$param?"{
action = { "admin_${params.adminAction}" }
}
The key is NOT to name the parameter as "action", because it seems to be directly mapped to an action and can not be overriden.
I also tried a dynamic solution with generic prefixes and it seems to work as well:
"/$prefix/$controller/$adminAction?/$param?"{
action = { "${params.prefix}_${params.adminAction}" }
}
I didn't test it, but try this:
"mysite/$prefix/$controller/$method/$id?"{
action = "${prefix}_${method}"
}
It constructs the action name from the prefix and the method.
Just take a look on grails URL Mappings documentation part
The action I target needs https. I already have a filter in place that redirects to https if a request comes in via http, but I would prefer to send the request via https right from the start.
EDIT
There was an answer from Darin (updated now to something else ) where he asked why I call this first action by http anyway. He had a good point there and I just updated a couple of links. This was the easiest and securest way to fix my problem.
Once I find the time to evaluate çağdaş answer I will use this as the correct answer, because I guess thats of interest for some other people (...including me in the future)
I don't know if you must use RedirectToAction but with a UrlHelper and the controller's Redirect method you can do this :
public ActionResult SomeAction() {
UrlHelper u = new UrlHelper(this.ControllerContext.RequestContext);
return Redirect(u.Action("actionName", "controllerName", null, "https"));
}
ASP.NET MVC 3 includes the RequireHttpsAttribute which may be of assistance.
Up until now I've been able to get away with using the default routing that came with ASP.NET MVC. Unfortunately, now that I'm branching out into more complex routes, I'm struggling to wrap my head around how to get this to work.
A simple example I'm trying to get is to have the path /User/{UserID}/Items to map to the User controller's Items function. Can anyone tell me what I'm doing wrong with my routing here?
routes.MapRoute("UserItems", "User/{UserID}/Items",
new {controller = "User", action = "Items"});
And on my aspx page
Html.ActionLink("Items", "UserItems", new { UserID = 1 })
Going by the MVC Preview 4 code I have in front of me the overload for Html.ActionLink() you are using is this one:
public string ActionLink(string linkText, string actionName, object values);
Note how the second parameter is the actionName not the routeName.
As such, try:
Html.ActionLink("Items", "Items", new { UserID = 1 })
Alternatively, try:
Items
Can you post more information? What URL is the aspx page generating in the link? It could be because of the order of your routes definition. I think you need your route to be declared before the default route.
Firstly start with looking at what URL it generates and checking it with Phil Haack's route debug library. It will clear lots of things up.
If you're having a bunch of routes you might want to consider naming your routes and using named routing. It will make your intent more clear when you re-visit your code and it can potentially improve parsing speed.
Furthermore (and this is purely a personal opinion) I like to generate my links somewhere at the start of the page in strings and then put those strings in my HTML. It's a tiny overhead but makes the code much more readable in my opinion. Furthermore if you have or repeated links, you have to generate them only once.
I prefer to put
<% string action = Url.RouteUrl("NamedRoute", new
{ controller="User",
action="Items",
UserID=1});%>
and later on write
link
Html.ActionLink("Items", "User", new { UserID = 1 })