You are currently browsing the tag archive for the ‘SharePoint’ tag.

SharePoint: Using custom HttpHandler to Response.Redirect() users

This post generated from a question at StackOverflow; the question raised was, to how to redirect users in SharePoint using custom HttpHandler, when you do not have access to the server – or – have no permission to access the server/configuration.

HttpHandlers are used by IIS to “handle” different document types, for instance you have separate .asmx handle, .aspx handler, .ascx handler, etc.

Workaround 1: Look into SPUtility.Redirect

You can use the SPUtility.Redirect method whenever you want to direct the user to a different page. For example, you might create a landing page that determines the user’s role membership, and based on that information you can redirect them to an appropriate page. Or, based on the contents of a query string issued by the user’s browser, you might redirect them to a page that can process the query string, such as the Search Center results page.

Workaround 2: Disposable Windows SharePoint Services
Alternatively, you can look into Using Disposable Windows SharePoint Services Objects.

Workaround 3: Custom Handler in SharePoint
Create a custom HttpHandler in Windows SharePoint Services 3.0; whenever a user requests a url, your custom HttpHandler is going to process that. .Redirect() if you like the url, else otherwise.

But for your custom HttpHandler to work, it should be called first – so in your config file you will have to provide the value in path. Usually an extension is added here. But you can replace that with a * to work for all request. I believe that would work.

Workaround 4:
Assuming that you have “access” to pages so that you can write javascript in it, you can use the javascript in following way.


function RedirectIfUnAuthorized()
{
//Get the location of the current page.
var currentUrl = new String( document.location.href )

//See if it belongs to the urls you are looking for; redirect if so.
if (currentUrl == "http://www.thisUrl.com/page1.aspx") {Response.Redirect("http://www.GOOGLE.com")}
if (currentUrl == "http://www.thisUrl.com/page2.aspx") {Response.Redirect("http://www.BING.com")}
if (currentUrl == "http://www.thisUrl.com/page3.aspx") {Response.Redirect("http://www.someother.com")}
}

Happy coding!

Advertisements
%d bloggers like this: