fttphandler

R

rony.vainblat

hi ,
i am building site that the user can enter by virtual path .
for example www.mysite.com/car/bigCars/Mec/default.aspx
this path "/car/bigCars/Mec/default.aspx" do not exist .
what i what is that my jttphandler will catch the url , and user will
surf the site
thinking he is actually in that url .
what i did is that i do catch the url and i transferring him to
anouther page by preserving the url that the user entered .

ok , so the problem goes like that ,
i have link in the page that i did server.transfer to the user and i
want that to preserve
the url to . instead i am getting "page not found" .


how do i do that ?
Please help .


this is my code :
Handler :


public class DomainHandler : IHttpHandler
{
public void ProcessRequest(HttpContext context)
{
context.Response.Write(context.Request.Url.ToString());
context.Server.Transfer("/WebSite/CategoryPage.aspx");
}
public bool IsReusable
{
get
{
return true;
}
}
}


web.config :
<httpHandlers>
<add verb="*" path="default.aspx"
type="DomainFilter.DomainHandler"/>
</httpHandlers>
 
T

Tasos Vogiatzoglou

HttpHandlers must be also registered in IIS.

Open IIS management tool, right click on the virtual directory,
Properties and click the "Configuration" button in the first tab.

Then add C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\aspnet_isapi.dll
for the .* files with "Check That files exist" checkbox unchecked.

Hope this helps.

Regards,
Tasos
 
R

rony.vainblat

thanks ,
but i did it with vitual files .
public class DomainHandler : IHttpHandler
{
protected const string siteName = "WebSite";
protected const string firstRunFile = "default.aspx";

#region GetLogicPath
/// <summary>
/// set the physical path
/// </summary>
/// <param name="requestedUrl">the url</param>
/// <param name="runFile">the virtual file that runs</param>
/// <returns>returns the path to be match the physical path in the
web.config</returns>
protected string GetLogicPath(string requestedUrl, string runFile)
{
int fileL = Path.GetFileName(requestedUrl).Length;
int runFileL = runFile.Length;
return requestedUrl.Substring(0, siteName.Length + 2) +
requestedUrl.Substring(requestedUrl.Length - runFileL);
}
#endregion

public void ProcessRequest(HttpContext context)
{
string requestedUrl;
string targetUrl;
string newUrl;
string param = string.Empty;
string runFile = string.Empty;

requestedUrl = context.Request.RawUrl;
newUrl = requestedUrl;
runFile = Path.GetFileName(requestedUrl);
if (requestedUrl.Length != 21)
{
if (requestedUrl.IndexOf("?") >= 0)
{
runFile = runFile.Substring(0, runFile.IndexOf("?"));
newUrl = GetLogicPath(requestedUrl.Substring(0,
requestedUrl.IndexOf("?")),runFile);
param =
requestedUrl.Substring(requestedUrl.IndexOf("?"));
}
else
{
newUrl = GetLogicPath(requestedUrl, runFile);
}
}
targetUrl = ConfigurationManager.AppSettings[newUrl];
if (targetUrl!=null)
context.Server.Transfer(targetUrl + param);
}

<appSettings>
<add key="ConnectionString" value="user id=ChadMart; data
source=TEAM; initial catalog=ChadMart;pwd=kiska01"/>
<add key="FieldPerPage" value="4"></add>
<add key="PagePerWindow" value="5"></add>
<add key="url" value="http://localhost:2998/Website/"></add>
<add key="/WebSite/default.aspx"
value="~/Front/CategoryPage.aspx"/>
<add key="/WebSite/Items.aspx" value="~/Front/ItemsFrames.aspx"/>
<add key="/WebSite/ItemsS.aspx" value="~/Front/ItemSite.aspx"/>
<add key="/WebSite/head.aspx" value="~/Front/header.aspx"/>
<add key="/WebSite/ErrorMsg.aspx" value="~/Front/Error.aspx"/>
</appSettings>

<system.web>
<httpHandlers>
<add verb="*" path="*/Front/*.aspx"
type="System.Web.UI.PageHandlerFactory"/>
<add verb="*" path="*.aspx" type="DomainHandler"/>
</httpHandlers>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top