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 (http://www.codeproject.com/aspnet/urlrewriter.asp) and then my code below :
My aspx page:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="TestURLRewriter.aspx.cs" Inherits="TestURLRewriter" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" ><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); } }