重写所有 url 将 aspx 扩展名更改为 html

发布于 2024-12-01 08:45:49 字数 260 浏览 0 评论 0原文

我是 iis url 重写模块的新手,我不知道如何做到这一点。

例如我有这个网址:

http://localhost/section.aspx?x=section1&IDSection=45

我想要这个:

http://localhost/section~x~section11~IDSection~45.html

有什么想法吗? 感谢您的帮助。

I'm new in the iis url rewrite module and i not how to do this.

for example i have this url:

http://localhost/section.aspx?x=section1&IDSection=45

And i want this:

http://localhost/section~x~section11~IDSection~45.html

Any ideas?
Thanks for your help.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

岁吢 2024-12-08 08:45:49

您需要做的是编写一个处理程序。这样您就可以捕获扩展名,然后根据需要对其进行解析。这对用户来说是不可见的。
处理程序绝对是您想要的方式,就好像您使用 URL 路由一样,您仍然需要在 IIS 中将处理程序从 aspx 更改为 html。

What you need to do is write a handler. That way you can capture the extension and then parse it as needed. This will be invisible to the user.
Handler is definitely the way you want to go as if you use URL Routing, you will still need to change the handler from aspx to html in IIS.

我很OK 2024-12-08 08:45:49

这是在 IIS7 中使用 URL 重写模块的解决方案:

  • 创建新的空白入站规则
  • 模式为: ^section~x~([_0-9a-z-]+)~IDSection~([0-9]+).
  • html重写操作:Section.aspx?x={R:1}&IDSection={R:2}
  • 创建新的黑色出站规则
  • 使用以下格式创建新前提条件:
    • 条件输入:{RESPONSE_CONTENT_TYPE}
    • 模式:^text/html
  • 模式为:^Section.aspx\?x=([_0-9a-z-]+)(?:&|&)IDSection= ([0-9]+)$
  • 以及重写​​操作:Section~x~{R:2}~IDSection~{R:2}.html

this is the solution using URL Rewrite module in IIS7:

  • Create new blank inbound rule
  • The patterns is: ^section~x~([_0-9a-z-]+)~IDSection~([0-9]+).html
  • The rewrite action: Section.aspx?x={R:1}&IDSection={R:2}
  • Create new black outbund rule
  • Create new precondition with the next format:
    • Condition input: {RESPONSE_CONTENT_TYPE}
    • Pattern: ^text/html
  • The pattern is: ^Section.aspx\?x=([_0-9a-z-]+)(?:&|&)IDSection=([0-9]+)$
  • And the rewrite action: Section~x~{R:2}~IDSection~{R:2}.html
娇妻 2024-12-08 08:45:49

您可以在 C# 中执行此操作,以便在 ASP.NET 中的 URL 中使用自定义扩展。

protected void Application_BeginRequest(object sender, EventArgs e)
   {
    HttpApplication app = sender as HttpApplication;
    if (app.Request.Path.ToLower().IndexOf(".html") > 0)
    {
        string rawpath = app.Request.Path;
        string path = rawpath.Substring(0, rawpath.IndexOf(".html"));
        app.Context.RewritePath(path+".aspx");
    }
}

You can do this in c# to use a customized extension in your URL in ASP.NET.

protected void Application_BeginRequest(object sender, EventArgs e)
   {
    HttpApplication app = sender as HttpApplication;
    if (app.Request.Path.ToLower().IndexOf(".html") > 0)
    {
        string rawpath = app.Request.Path;
        string path = rawpath.Substring(0, rawpath.IndexOf(".html"));
        app.Context.RewritePath(path+".aspx");
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文