1

I'd like to encrypt all my urls on a sharepoint site. I'm running on Sharepoint Server 2013. and I'd like to have instead of http://www.site.com/pages/page.aspx something like http://www.site.com/kqfhglifgldsiqugfez

1
  • Don't reask the same question please Nov 12, 2013 at 17:16

2 Answers 2

0

Suggest you start your search by seeing what the IIS Rewrite Module can do for you, it's not clear from the question if you are looking to obfuscate the url, encode the url or simply disguise it when on page. Needs more info tbh.

MS URL re-Write Module Link

0

you need to use:

SPEncode.UrlEncode

http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.utilities.spencode.urlencode.aspx

the key is to have a httpmodule triggered on page load, add the code above to:

string EncodedUrlString = SPContext.Current.Site.URL + SPEncode.UrlEncode(SPContext.Current.Web.ServerRelativeUrl);

Context.Response.Redirect(EncodedUrlString);

you might notice that it will loop every time the page is loaded ;) going in circles!

you have two methods you can do here! 1 decode the current url fir and check to see if its been encoded!

or

just save the url in memeory and compare before you encode ;)

public string SavedURl
{
    get
    {
        return Page.Session["Saveurl"] as string;
    }
    set
    {
        Page.Session["Saveurl"] = value;
    }
}

have that method to save the value.

within the onload event or what ever it may be do the following:

//save the current url that is not encoded
string currentURl = SPContext.Current.Site.URL + SPContext.Current.Web.ServerRelativeUrl;

//check to see if its a new page that is not encoded
if (SavedURl == null || SavedURl != currentURl)
{
      //encode the url
      string EncodedUrlString = SPContext.Current.Site.URL + SPEncode.UrlEncode(SPContext.Current.Web.ServerRelativeUrl);
      //save the actual url for postback check
      SavedURl = currentURl;
      //redirect to the encoded url
      Context.Response.Redirect(EncodedUrlString);
}

i might of missed somthing out here but you should get the idea of where im going! you might notice that the page loads and shows the origional url and then reloads.... that would be on the onload event! so you need to look into the event tree to catch the httprequest and response before its sent to the ui... somthing like onInit event. Have a look at this module:

http://social.msdn.microsoft.com/Forums/en-US/68b79f9f-0534-4f7e-99a5-8c8663dc1202/sharepoint-custom-error-httpmodule-gives-cannot-redirect-after-http-headers-have-been-sent-error?forum=sharepointdevelopmentprevious

my tip of the day, be carefull as to what your encoding! you might not want to encode all pages on a sharepoint site! some pages could look encoded but are not, rather they are auto generated when creating list, librarys or from workflows or custom pages pulled together from the server ect that you could break ;).

Not the answer you're looking for? Browse other questions tagged or ask your own question.