Search code examples
c#asp.netweb-configglobalapp-code

ASP.NET C#: How can I call App_code functions inside of web.config


This is the code I use in the web.config:

<add name="MainRule" virtualUrl="^~/Pages/([\w-_]+).html"
  rewriteUrlParameter="ExcludeFromClientQueryString"
  destinationUrl="~/page.aspx?pid=${PageTitleToId.ConvertPageTitleToPageId($1)}"
  ignoreCase="true" />

In the App_Code folder I have a "PageTitleToId.cs" class which contains the ConvertPageTitleToPageId function which takes a string parameter.

Am I missing something because the ConvertPageTitleToPageId function is not called when I run the page.

Any help is appreciated,

Simplecode


Solution

  • You can't execute code in your web.config. I would update page.aspx to handle a title query string parameter on which it calls ConvertPageTitleToPageId() to get your pid.