Copied to clipboard

Flag this post as spam?

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


  • Ismail Mayat 4511 posts 10059 karma points MVP 2x admin c-trib
    Mar 18, 2015 @ 17:19
    Ismail Mayat
    0

    Alias ajaxlink to controller

    Using umbraco 6.1.6 and I have a surface controller called CommentSurface in there I have method AddLike.  I call the method using ajax link code looks like

    @Ajax.ActionLink(GetLikeLabel("Site.Pages.Product.Review.Likes", comment.Likes, umbraco),
                                    "AddLike",
                                    "CommentSurface",
                                    new { commentId = comment.Id, like = true },
                                    GetLIkeAjaxOptions(comment, umbraco, "true")

     

    This renders link html that looks like

    <a class="thumbs--up icon icon--15" data-ajax="true" data-ajax-failure="$('#likeResult-1254').html('<p>You have already liked this comment</p>')" data-ajax-loading="#loadingComments" data-ajax-method="GET" data-ajax-mode="after" data-ajax-success="(function(){likeSuccess('1254',true,'.comment--item');})();" data-ajax-update="#likeResult-1254" href="/umbraco/Surface/CommentSurface/AddLike?commentId=1254&amp;like=True" id="like1254">Like</a>

    This all works fine.  The issue is on our live server we have url rules set up so that the umbraco backoffice cannot be hit  so any url /umbraco will redirect to home page.  What I am planning to do is add url rewrite in web.config so that i can make call like /somesite/Surface/CommentSurface/AddLike and that will resolve to /umbraco/Surface/CommentSurface/AddLike.  

    So the question is on a controller and method in controller is there any kind of attribute to create a different url so instead of 

    /umbraco/Surface/CommentSurface/AddLike

    I can get 

    /somesite/Surface/CommentSurface/AddLike

    and use url rewrite to resolve to right place.

    Regards

     

    Ismail

  • Matt Brailsford 2958 posts 15629 karma points MVP 7x c-trib
    Mar 18, 2015 @ 17:29
    Matt Brailsford
    0

    Hey Ismail,

    For it to be a surface / umbraco api controller, I don't think there is a way to get /umbraco out of the url. The only way I can think to do it is by using a bog standard controller / api controller, and registering your own route just like you would in a regular mvc app. The only down side is you wouldn't get access to any of the convenience methods in the controller (but then if you are accessing it via ajax, I don't think you'll need any of the "redirect to current page" type functions).

    Matt

  • Matt Brailsford 2958 posts 15629 karma points MVP 7x c-trib
    Mar 18, 2015 @ 17:34
    Matt Brailsford
    0

    Actually, looking at how surface controllers are registered, you could replace /umbraco in the URL by changing the umbracoPath in the web.config. But I don't thing that will help you much, as you'd then need your rewrites to block that path for any url that isn't a surface controller / api controller aswell.

    Matt

  • Ismail Mayat 4511 posts 10059 karma points MVP 2x admin c-trib
    Mar 18, 2015 @ 18:43
    Ismail Mayat
    100

    Matt,

    According to docs https://msdn.microsoft.com/en-us/library/system.web.mvc.ajax.ajaxoptions%28v=vs.118%29.aspx there is AjaxOptions object it has url parameter you can set that and in the rendered html you get data-ajax-url and it uses that.  You still get href as the full umbraco url.  So I am going to go with this time to do some url re writes ;-}

    Regards

     

    Ismail

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies