dinsdag 10 januari 2012

How to create a Redirection Page in Sharepoint 2010

In Sharepoint different solutions are possible if you want to create 
a redirection page. 
1) You can create a .aspx page that you deploy in the layouts folder 
and programmaticaly call the response.redirect(url) function in the code behind 
of your page in the page_load function. Advantage of this solution is that you can add additional
code to your aspx page for example to encrypt the url parameters.
Disadvantage, you need to deploy your solution on your sharepoint Farm. 
In some organisations you have to ask to your administrator 
for the deployment what can give some delay and administration.

2) Create a webpart page in Sharepoint and add the Content Editor Web Part 
to a zone of your choice. It doesn't really matter since users won't be using the page.
Go to the HTML source of your Content Editor Web part and add next line of code if you want
the user to let them change there bookmarks...



<SCRIPT type='"text/javascript"'>// <![CDATA[
alert("This site has been moved to another location, please update all existing bookmarks.  You will be redirected momentarily.");
// ]]></SCRIPT>
 
for the redirection you add next line of code behind the script part :
 
 
 <meta http-equiv="refresh" content="10;url=http://MYSERVERNAME.com/Pages/default.aspx">
 
Advantage of this solution, no need of administrators for the deployment of your solution. 
Disadvantage, you cannot add additional development code to the server side.
 
 3) Create in Visual Studio 2010 a sandbox solution and add a web part to your project. 
 In the webpart you can add additional code for generating the url.  
 For example calculate parameters for your redirection. 
 But you cannot redirect to your new page from the code begint. 
 You need to add programmaticaly some scripting code to your webpart page for the redirection. 
 This script can be very easy:
 
  <script language="text/javascript>
   window.location = yournewurl;
  </script>
 
After deploying your Sandbox solution you can add your webpart to a webpart page 
and the redirection will happen immediately.

Advantage, you can use extra development code in your webpart for calculations. 
Also you can easely upload yourself your webpart to your Sharepoint Collection in 
the Solutions library, and activate it.
Disadvantage, you need to take care about the limitations of Sandbox solutions. 

 

Geen opmerkingen:

Een reactie posten