Introduce DataBase,Asp.net,JavaScript,Xml,Html,Css,Sql,Php,ASP.NET Controls,AJAX,Tools,HTML,CSS,JavaScript,Open Source Project,WPF,.Net Framework,Linq
Top Recommended Hosting

Problem redirecting a page from httpmodule

by the3factory 5/10/2008 8:02:00 PM
Question:

Hi,

There are two pages one for the Admin and other for the normal user.Depending on the user they need to be redirected to a different page.I am writing the logic for the redirection in the httpmodule beginrequest handler.Both the pages share a common suffix(dashboard).But on being redirected I am entering into an infinite loop.Is there a way to stop the iteration once the redirection is done the first time??I am attaching a sample code 

void context_BeginRequest(object sender, EventArgs e)

{

//method1 populates the cookie with values from a DB call

//the code below is a sample

if(HttpContext.Current.Request.RawUrl.Contains("Dashboard.aspx"))

if(user=="Admin")

{

 HttpContext.Current.RewritePath("AdminDashboard.aspx");

}

else

{

HttpContext.Current.RewritePath("UserDashboard.aspx");

}

}

}

 

Thank you in advance!


Answer1:

Yes, you must be in infinite loop. You are checking if url contains Dashboard.aspx. Both - AdminDashboard.aspx and UserDashboard.aspx contain Dashboard.aspx. Instead of

if(HttpContext.Current.Request.RawUrl.Contains("Dashboard.aspx"))

you should check out if request is made to page calles Dashboard.aspx. To do this you have to check Reuqest object's path properties.


Related posts

Sign up for PayPal and start accepting credit card payments instantly.


Powered by BlogEngine.NET 1.2.0.0