简体   繁体   English

ASP.NET C#:如何在 web.config 中调用 App_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:这是我在 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.在 App_Code 文件夹中,我有一个“PageTitleToId.cs”class,其中包含带有字符串参数的 ConvertPageTitleToPageId function。

Am I missing something because the ConvertPageTitleToPageId function is not called when I run the page.我是否遗漏了什么,因为在我运行页面时未调用 ConvertPageTitleToPageId function。

Any help is appreciated,任何帮助表示赞赏,

Simplecode简单代码

You can't execute code in your web.config.您无法执行 web.config 中的代码。 I would update page.aspx to handle a title query string parameter on which it calls ConvertPageTitleToPageId() to get your pid .我会更新page.aspx以处理title查询字符串参数,在该参数上它调用ConvertPageTitleToPageId()来获取您的pid

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 为什么我不能在我的代码asp.net c#中使用app_code中的代码文件 - why I can't use code files from app_code in my code asp.net c# 我可以在ASP.NET网站的CodeFile之外的App_Code的C#文件中使用类/函数吗? - Can I use class/function in C# file in App_Code besides the CodeFile for an asp.net website? ASP.Net c# - 如何在App_Code类中实例化WebUserControl的实例? - ASP.Net c# - How do I instantiate an instance of a WebUserControl from within a App_Code class? 如何从app_code中的类设置母版页中的属性? 与asp.net C# - How to set property in master page from class in app_code? with asp.net c# C#/ ASP.Net:app.settings而不是web.config - C#/ASP.Net: app.settings instead of web.config 可以在asp.net c#中将web.config键值对用作编译时常量吗? - Can a web.config key value pair be used as a compile time constant in asp.net c#? 如何以编程方式修改 ASP.NET MVC 和 C# 应用程序中的 web.config? - How to programmatically modify web.config in ASP.NET MVC and C# application? 如何使用web.config文件在ASP.NET/C#中用参数重写URL - How to rewrite an url with parameters in ASP.NET/C# using web.config file 在dll中调用Activator.CreateInstance来实例化位于Asp.Net App_Code中的实例类 - Call Activator.CreateInstance in a dll to intance class that reside inside Asp.Net App_Code 在ASP.Net App_Code文件夹中混合C#和VB.Net - Mixing C# and VB.Net in ASP.Net App_Code folder
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM