0

I have dynamic urls to put in my webpage. Currently what i am doing is map those urls using url rewriter module in iis. That should be pre-configured. And I saw those rules in web.config

Anyhow I cannot get pre knowledge about urls that I am getting. As an example: for this question urls will be

what I want to put in my web application is MyWeb/ans1, MyWeb/ans2, MyWeb/ans3, myWeb/ans4

Therefore I need to have four rules in my rewriter (in this case).

I want to achieve url re writting thing in dynamically(run time). I can not predefine those rules. Is there any work arround to achieve this? put those rules to database table and fetch it, calling action method and do the rewrtting part. Or why can't I do this.

Thanks

Community
  • 1
  • 1
syard gate
  • 85
  • 12

1 Answers1

0

You could try ManagedFusion.net, an opensource Url rewriter project which give much more power than IIS rewrite module. See http://managedfusion.com/products/url-rewriter/documentation.aspx.

You can pre-configure rules in it's configuration file and you CAN implement you own ApacheEngine to run dynamic rules.

public class SpidermanApacheEngine : ApacheEngine
{
    /// <summary>
    /// Runs the rules.
    /// </summary>
    /// <param name="context">The context.</param>
    /// <returns>the redirect Uri</returns>
    public override Uri RunRules(HttpContextBase context)
    {
        // you can define any dynamic rule here.
    }
}

And replace the default ManagedFusion engine with yours in web.config:

<managedFusion.rewriter xmlns="http://managedfusion.com/xsd/managedFusion/rewriter">
    <rules engine="Other" engineType="Spiderman.ManagedFusionRewriter.SpidermanApacheEngine, Spiderman.ManagedFusionRewriter">
    </rules>
    <rewriter allowVanityHeader="false" />
</managedFusion.rewriter>
Junius
  • 331
  • 2
  • 10
  • is this works like url rewrting plugin, I didnt get apache engine thing. And how this access my dynamic rules? – syard gate Mar 20 '14 at 08:38
  • it's HttpModule. Here is more detail. https://urlrewriter.codeplex.com/ and https://urlrewriter.codeplex.com/SourceControl/latest#src/Engines/ApacheEngine.cs. Implement your engine and defines dynamic rules in "public override Uri RunRules(HttpContextBase context)" method. context contains the current target url(http://yousite/a/b/c) and you can return any other URI(http://anysite/d/e/f) you wanted then request will forward to the new URI – Junius Mar 21 '14 at 04:20