简体   繁体   English

在C#或VB.net中使用IIS出站重写

[英]Use IIS Outbound Rewrites in C# or VB.net

Using IIS URL Rewrite one can rewrite URLs at response time in IIS. 使用IIS URL重写可以在响应时在IIS中重写URL。 I want to be able to do this from codebehind so that I can save a file with rewritten URLs (such as sitemap.xml). 我希望能够从背后的代码中执行此操作,以便可以使用重写的URL(例如sitemap.xml)保存文件。 Is this possible in VB/C#? 在VB / C#中可以吗? I can't seem to find any built in way to do this. 我似乎找不到任何内置方法来执行此操作。

Alternatively, is there any way with Outbound rules through IIS to ReWrite URLs that are inside the innerHTML of a specific html item, and not an attribute? 另外,通过IIS出站规则是否可以重新写入特定html项的innerHTML内的URL,而不是属性?

I've started to write my own .NET class to do this (load rewrites from web.config on class instantiation, the call a function passing the unwritten URL to receive back a rewritten one), but while the basic solution to get simpler rewrites working is quite trivial, the complete solution doesn't seem to be trivial at all. 我已经开始编写自己的.NET类来做到这一点(在类实例化时从web.config加载重写,调用传递未写URL的函数以接收重写的URL),但是获得更简单重写的基本解决方案工作非常琐碎,完整的解决方案似乎一点也不琐碎。

I actually found the answer here: 我实际上在这里找到了答案:

http://forums.iis.net/t/1163122.aspx?Rewriting+javascript+code+possible http://forums.iis.net/t/1163122.aspx?Rewriting+javascript+code+possible

You can rewrite the links within the javascript code by using outbound rewrite without specifiy the matching scope. 您可以使用出站重写来重写javascript代码中的链接,而无需指定匹配范围。 The rule looks like: 规则如下:

  <rule name="Rewrite internal link"> <match filterByTags="None" customTags="" pattern="https://internal/" /> <action type="Rewrite" value="https://extenal/" /> </rule> 

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM