Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

aspx page not loading. C# Method loading before page loads.

Status
Not open for further replies.

expresso100

Programmer
Aug 6, 2006
6
US
Why isn't my aspx page rendering before the process() method call? What is
happening is when I run my page in debug mode, my aspx page never renders, and it's jumping straight into my process() method when I run in debug mode in VS 2005, using the VS
built-in web engine.

What should happen is I start debug, my aspx page loads, I click on the hyperlink, and that initiates process() to run. It's not happening that way though, why?

See related article here ( and then my code below. I don't know what I should do:

My aspx page:


<%@ Page Language="C#" AutoEventWireup="true"
CodeFile="TestURLRewriter.aspx.cs" Inherits="TestURLRewriter" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"
<html xmlns=" >
<head id="Head1" runat="server">
<title>URL Rewriter Test Page</title>
</head>
<body>
<asp:HyperLink ID="link1" NavigateUrl="/recipes/4/detail.aspx"
runat="server">/recipes/4/detail.aspx</asp:HyperLink>

</body>
</html>


My global.asax:


void Application_BeginRequest(object sender, EventArgs e)
{
MyNamespace.Web.URLRewriter.Process();
}
...rest of global.asax...



My .cs page:


namespace MyNamespace.Web
{
public class URLRewriter : IConfigurationSectionHandler
{
protected XmlNode _oRules;

protected URLRewriter(){}
private string recipeID;

public static void Process()
{
URLRewriter oRewriter =
(URLRewriter)ConfigurationSettings.GetConfig("system.web/urlrewrites");

string rewrittenURL =
oRewriter.GetRewrittenURL(HttpContext.Current.Request.Path);

if (rewrittenURL.Length > 0)
{
//Rewrite the path using the rewritten URL
HttpContext.Current.RewritePath(rewrittenURL);
}
}
 
for ASP.NET related questions: ASP.NET Forum: forum855

Check out this link: - especially the example at the bottom. In the example you'll notice that the BeginRequest event will fire before the page is processed (or even loaded - otherwise it wouldn't know where to find it). This means that the .Process() method will be invoked before the page does anything (which is the intended behaviour of a URL re-write - to rewrite the requested url so that it references a real local page before loading it). Also, the BeginRequest event will be fired for every request specified within the rules of the urlrewrite config (in web.config) - you haven't shown these rules here, but you need to see whether they would return true in a regular expression for the page you're currently loading.

A smile is worth a thousand kind words. So smile, it's easy! :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top