G
Guest
I need to perform url rewriting to convert this (for example):
/blogs/feeds/popular/posts/
to this:
/blogs/feeds.aspx?type=popular&type2=posts
What I did was the following:
1. Created an http handler that parses the url and based on it will execute
another aspx page using Server.Execute
2. In the IIS I added ".*" to the ISAPI handler to be handled by .net
3. In web.config I added this so that it handles all urls coming in:
<httpHandlers>
<add verb="*" path="*/" type="MyHandler.FeedsHandler, FeedsHandler" />
</httpHandlers>
My question is: Is this a proper practice or are there any down sides to
using "server.execute" and "Setting the ISAPI handler to handle .* as .net
pages"?
Following is my handler code:
using System;
using System.Web;
using System.Configuration;
namespace MyHandler
{
/// <summary>
/// Summary description for FeedsHandler.
/// </summary>
public class FeedsHandler : IHttpHandler
{
#region Implementation of IHttpHandler
public void ProcessRequest(System.Web.HttpContext context)
{
HttpResponse objResponse = context.Response;
string myPath = context.Request.Path;
if (myPath.Contains("/feeds/"))
{
string[] mySplitPath = myPath.Split('/');
string myType2 = mySplitPath[mySplitPath.Length - 2];
string myType = mySplitPath[mySplitPath.Length - 3];
HttpContext.Current.Server.Execute("/feeds/feeds.aspx" +
"?type=" + myType + "&type2=" + myType2);
}
else
{
HttpContext.Current.Server.Execute(myPath + "Default.aspx");
}
}
public bool IsReusable
{
get
{
return false;
}
}
#endregion
}
}
/blogs/feeds/popular/posts/
to this:
/blogs/feeds.aspx?type=popular&type2=posts
What I did was the following:
1. Created an http handler that parses the url and based on it will execute
another aspx page using Server.Execute
2. In the IIS I added ".*" to the ISAPI handler to be handled by .net
3. In web.config I added this so that it handles all urls coming in:
<httpHandlers>
<add verb="*" path="*/" type="MyHandler.FeedsHandler, FeedsHandler" />
</httpHandlers>
My question is: Is this a proper practice or are there any down sides to
using "server.execute" and "Setting the ISAPI handler to handle .* as .net
pages"?
Following is my handler code:
using System;
using System.Web;
using System.Configuration;
namespace MyHandler
{
/// <summary>
/// Summary description for FeedsHandler.
/// </summary>
public class FeedsHandler : IHttpHandler
{
#region Implementation of IHttpHandler
public void ProcessRequest(System.Web.HttpContext context)
{
HttpResponse objResponse = context.Response;
string myPath = context.Request.Path;
if (myPath.Contains("/feeds/"))
{
string[] mySplitPath = myPath.Split('/');
string myType2 = mySplitPath[mySplitPath.Length - 2];
string myType = mySplitPath[mySplitPath.Length - 3];
HttpContext.Current.Server.Execute("/feeds/feeds.aspx" +
"?type=" + myType + "&type2=" + myType2);
}
else
{
HttpContext.Current.Server.Execute(myPath + "Default.aspx");
}
}
public bool IsReusable
{
get
{
return false;
}
}
#endregion
}
}