<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Scared Panda &#187; ASP.Net</title>
	<atom:link href="http://scaredpanda.com/tag/aspnet/feed/" rel="self" type="application/rss+xml" />
	<link>http://scaredpanda.com</link>
	<description>Local T-Shirts For Local Causes</description>
	<lastBuildDate>Thu, 29 Jul 2010 18:44:54 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>SharePoint Vanity URL Rewriting</title>
		<link>http://scaredpanda.com/2010/01/sharepoint-vanity-url-rewriting/</link>
		<comments>http://scaredpanda.com/2010/01/sharepoint-vanity-url-rewriting/#comments</comments>
		<pubDate>Thu, 28 Jan 2010 17:44:05 +0000</pubDate>
		<dc:creator>Clint</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[ASP.Net]]></category>
		<category><![CDATA[SharePoint]]></category>

		<guid isPermaLink="false">http://scaredpanda.com/?p=321</guid>
		<description><![CDATA[During the day I am a software engineer and from time to time I tend to come up with some cool solutions that I think other developers would be interested in. So going forward I will be posting some code that I have built and want to share with all you other nerds out there. Here goes!

Looking around the internet I've seen that many people have been trying to implement URL rewriting in a MOSS environment. Ive implemented url redirecting with MOSS using the HTTP module route for a while now and I've documented the code I used and what parameters worked the best for me here;

Take a look and let me know if this helps you and if you have any questions. Make the jump to see the code and enjoy.]]></description>
			<content:encoded><![CDATA[<p>During the day I am a software engineer and from time to time I tend to come up with some cool solutions that I think other developers would be interested in. So going forward I will be posting some code that I have built and want to share with all you other nerds out there. Here goes!</p>
<p>Looking around the internet I&#8217;ve seen that many people have been trying to implement URL rewriting in a MOSS environment. Ive implemented url redirecting with MOSS using the HTTP module route for a while now and I&#8217;ve documented the code I used and what parameters worked the best for me here;</p>
<p>Take a look and let me know if this helps you and if you have any questions.</p>
<p>After messing around for a little bit it, I came up with a good way to do it. When I was looking for examples on the web there were a lot of people saying that it couldn&#8217;t be done. But in the end it actually didn’t take much to implement it. Here’s an HttpModule that I wrote to do the work.</p>
<p>The key pieces are the this.app.BeginRequest += new EventHandler(app_BeginRequest) which steps in front of the request and allows the module to get its redirect on. And HttpContext.Current.RewritePath(redirect, false); will push the necessary headers n such forward so that the receiving .aspx page will understand how to correctly post back.<br />
<code><br />
using System;<br />
using System.Data;<br />
using System.Data.SqlClient;<br />
using System.Reflection;<br />
using System.Collections;<br />
using System.Text;<br />
using System.Web;<br />
using System.Web.Caching;<br />
using System.Web.SessionState;<br />
using System.Security.Cryptography;<br />
using System.Configuration;<br />
using System.Threading;<br />
using System.IO;<br />
using System.Security;<br />
using System.Security.Principal;</p>
<p>namespace ScaredPanda<br />
{<br />
    public sealed class RewriteHttpModule : IHttpModule<br />
    {<br />
        HttpApplication app = null;<br />
        ///<br />
        /// Initializes the httpmodule<br />
        ///<br />
        public void Init(HttpApplication httpapp)<br />
        {<br />
            this.app = httpapp;<br />
            this.app.BeginRequest += new EventHandler(app_BeginRequest);<br />
        }</p>
<p>        public void app_BeginRequest(Object s, EventArgs e)<br />
        {<br />
            try<br />
            {<br />
        //determine if the income request is a url that we wish to rewrite.<br />
        //in this case we are looking for an extension-less request<br />
                string url = HttpContext.Current.Request.RawUrl.Trim();<br />
                if (url != string.Empty<br />
                    &#038;&#038; url != "/"<br />
                    &#038;&#038; !url.EndsWith("/pages")<br />
                    &#038;&#038; !url.Contains(".aspx")<br />
                    &#038;&#038; url.IndexOf("/", 1) == -1)<br />
                {<br />
                    //this will build out the the new url that the user is redirected<br />
                    //to ie pandas.aspx?pandaID=123<br />
                    string redirect = ReturnRedirectUrl(url.Replace("/", ""));</p>
<p>            //if you do a HttpContext.Current.RewritePath without the 'false' parameter,<br />
                    //the receiving sharepoint page will not handle post backs correctly<br />
            //this is extremely useful in situations where users/admins will be doing a<br />
                   //'site actions'  event<br />
                   HttpContext.Current.RewritePath(redirect, false);<br />
                }<br />
            }<br />
            catch (Exception ex)<br />
            {<br />
                //rubbish<br />
            }<br />
        }<br />
    }<br />
}</code></p>
<div class='dd_post_share'><div class='dd_buttons'><div class='dd_button'><script src='http://widgets.digg.com/buttons.js' type='text/javascript'></script><a class='DiggThisButton DiggMedium' href='http://digg.com/submit?url=http://scaredpanda.com/2010/01/sharepoint-vanity-url-rewriting/&amp;title=SharePoint+Vanity+URL+Rewriting'></a></div><div class='dd_button'><iframe src='http://api.tweetmeme.com/button.js?url=http://scaredpanda.com/2010/01/sharepoint-vanity-url-rewriting/&amp;source=ScaredPanda&amp;style=normal' height='61' width='50' frameborder='0' scrolling='no'></iframe></div><div class='dd_button'><a name='fb_share' type='box_count' share_url='http://scaredpanda.com/2010/01/sharepoint-vanity-url-rewriting/' href='http://www.facebook.com/sharer.php'>Share</a><script src='http://static.ak.fbcdn.net/connect.php/js/FB.Share' type='text/javascript'></script></div><div class='dd_button'><iframe src='http://www.facebook.com/plugins/like.php?href=http://scaredpanda.com/2010/01/sharepoint-vanity-url-rewriting/&amp;show_faces=false&amp;layout=button_count'  width='90px' scrolling='no' frameborder='0' style='border:none; overflow:hidden; height:25px;' allowTransparency='true'></iframe></div><div class='dd_button'><script src='http://www.stumbleupon.com/hostedbadge.php?s=5&amp;r=http://scaredpanda.com/2010/01/sharepoint-vanity-url-rewriting/'></script></div><div class='dd_button'><a href='http://delicious.com/save' onclick="window.open('http://delicious.com/save?v=5&amp;noui&amp;jump=close&amp;url='+encodeURIComponent('http://scaredpanda.com/2010/01/sharepoint-vanity-url-rewriting/')+'&amp;title='+encodeURIComponent('SharePoint+Vanity+URL+Rewriting'),'delicious', 'toolbar=no,width=550,height=550'); return false;"><div class='delicious-normal-img'><img src='http://scaredpanda.com/wp-content/plugins/digg-digg/image/delicious.png' alt='Delicious' /><div class='delicious-normal-text' id='DD_DELICIOUS_AJAX_POST_ID'>Save</div></div></a></div></div></div><div style='clear:both'></div><!-- Social Buttons Shared Counts Generated by Digg Digg plugin v4.2, 
    Author : Yong Mook Kim
    Website : http://www.mkyong.com/blog/digg-digg-wordpress-plugin/ -->]]></content:encoded>
			<wfw:commentRss>http://scaredpanda.com/2010/01/sharepoint-vanity-url-rewriting/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
