Copied to clipboard

Flag this post as spam?

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


  • Ben 91 posts 111 karma points
    Aug 16, 2011 @ 15:01
    Ben
    0

    passing a long url to /base function

    hi,

    I have a "send comment" form, which includes a textarea where user can type up to 400 characters. U need it to be send to my /base and I do it wuth an ajax function. Since I must use a url like http://site.com/var1/var2/var3/var4, I can't send it to the ajax function(it's too long with the user textarea's text) and I get: 414 Request-Uri Too Long.

    Another error occurs when the user types characters like ':', '<', '>' that are considered as "special" or "unsafe". When I send those characters I get the status code: 400 Bad Request.
    I have to mention that I don't want to postback, so the solution has to be an ajax function that uses a /base function to send the information to the DataBase.
    Thanks from advance,
    Ben

     

  • Dirk De Grave 4541 posts 6021 karma points MVP 3x admin c-trib
    Aug 16, 2011 @ 15:19
    Dirk De Grave
    0

    Hi Ben,

    As you're limited to the number of chars on the url, you'd have to revert to using a postback to post the comment or use an update panel (which still does a postback but only refreshes portion of the page). And make sure to check the user's input for spammish data...

    Cheers,

    /Dirk

  • Comment author was deleted

    Aug 16, 2011 @ 15:26

    Or simply post params to the base url

    /base/var1/var2?tolongvar=blablabla

    And then in your base method fetch that param with

    HttpContext.Current.Request["tolongvar"]

  • Jeroen Breuer 4909 posts 12266 karma points MVP 6x admin c-trib
    Aug 16, 2011 @ 15:28
    Jeroen Breuer
    1

    You could also post your values to /base. Here is a sample with jQuery:

    jQuery:

    var url = SWFAddress.getPath();
    var baseUrl = location.protocol + '//' + location.host;
    $.post(baseUrl + '/base/Digibiz/GetHtmlUrl/', { url: encodeURIComponent(url) }, function (htmlUrl) {
    //do stuff

    /base method:

    public static string GetHtmlUrl()
    {
        //Get the url through a post because it can't be passed as a parameter because it contains slashes which don't work with /base.
        string url = HttpContext.Current.Server.UrlDecode(HttpContext.Current.Request["url"]);
    
        return UmbracoController.GetHtmlUrl(url);
    }

    This sample is also used here: http://our.umbraco.org/forum/templating/templates-and-document-types/16442-Use-jQuery-to-load-a-page-with-another-template#comment61539

    Jeroen

  • Ben 91 posts 111 karma points
    Aug 16, 2011 @ 15:33
    Ben
    0

    Hi Dirk,

    Thank you for your reply. I have to say that those are very bad news for me as I use ajax because the postback takes a lot of time.

    Is it good solution for me if I use an external webservice and a "normal" ajax function(type:post, dataType:json)  for raching this goal?

  • Ben 91 posts 111 karma points
    Aug 16, 2011 @ 15:39
    Ben
    0

    Chris and Jeoren, 

    Unfortunately, I can't use your suggested method because it's a problem when the user types non-eng characters in explorer, and then what is sent is a strign like "??????"

    Can you suggest other solutions?

    Thank you all.

  • Ben 91 posts 111 karma points
    Aug 17, 2011 @ 13:49
    Ben
    0

    it seems like the only solution is making a new webservice...

    works for me.

  • 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