Last post Oct 07, 2009 11:03 AM by HenrikBergstrom
Feb 28, 2009 06:31 PM|rockinthesixstring|LINK
Normally I would post this question in the UrlRewritingNet Forum, but I have noticed that there is not a lot of action in there.
I am creating all of my rules at runtime and am finding that sometimes the rules expire and I get a 404 error. I am wondering if anyone in here has some good knowledge of UrlRewritingNet and can give me some direction on what I might be doing wrong.
Public Class URLRewrite
Public Shared RewriteRulesExist As Boolean = False
Public Shared Sub CreateRewriteRules()
'create an integer for unique rule names
Dim i As Integer = 1
'iterate through the NavigationDataItem for each item
For Each o As NavigationDataItem In ICMS.Navigation.Settings.Instance
Dim rule As New UrlRewritingNet.Web.RegExRewriteRule()
rule.VirtualUrl = o.Url
rule.DestinationUrl = "~/Default.aspx?ID=" + o.ID.ToString
rule.IgnoreCase = True
rule.Rewrite = UrlRewritingNet.Web.RewriteOption.Application
rule.Redirect = UrlRewritingNet.Web.RedirectOption.None
rule.RewriteUrlParameter = UrlRewritingNet.Web.RewriteUrlParameterOption.ExcludeFromClientQueryString
UrlRewritingNet.Web.UrlRewriting.AddRewriteRule("URLRewriteRule" & i.ToString, rule)
'increment the integer
i = i + 1
'set ReWrite_Active to prevent having to call it on every request.
RewriteRulesExist = True
Public Shared Sub ReLoad_Rules()
RewriteRulesExist = False
End Sub 'Dispose_Rules
Protected Sub Application_BeginRequest(ByVal sender As Object, ByVal e As System.EventArgs)
'Set URL ReWriting Rules
If Not ICMS.URLRewrite.RewriteRulesExist Then
Thanks in advance for the direction!
Mar 01, 2009 12:36 AM|rockinthesixstring|LINK
Does anyone have any insight into this issue? It is nearly killing me since my app is useless without effective rewriting.
Thanks in advance!!!
Mar 07, 2009 12:05 AM|rockinthesixstring|LINK
Mar 19, 2009 05:22 AMfirstname.lastname@example.org|LINK
I had the same problem, rewrite rules just disappeared. So I chose to put rules in webconfig directly. I generated them in a xml file, then copy and paste to webconfig. I know it's a crappy way, but it works...
Oct 07, 2009 11:03 AM|HenrikBergstrom|LINK
Hi. I think we have the same problem.
We saw that the RewriteRuleCollection in UrlRewriteModule was null sometimes.
We think the problem is that different httphandlers is created and they are not always using the same RewriteRuleCollection. (maybe)
The quick solution is to set RewriteRuleCollection as static.
That solved our problem and we never had it again :)
public class UrlRewriteModule : IHttpModule
const string ItemsVirtualUrl = "UrlRewritingNet.UrlRewriter.VirtualUrl";
const string ItemsClientQueryString = "UrlRewritingNet.UrlRewriter.ClientQueryString";
const string ItemsRewriteUrlParameter = "UrlRewritingNet.UrlRewriter.RewriteUrlParameter";
const string ItemsCachedPathAfterRewrite = "UrlRewritingNet.UrlRewriter.CachedPathAfterRewrite";
public const string PhysicalPath = "UrlRewritingNet.UrlRewriter.CachedPathAfterRewrite";
private bool rewriteOnlyVirtualUrls = false;
private string _contextItemsPrefix = string.Empty;
private static RewriteRuleCollection _rewrites = null; // Changed to static.
Hope this help,