如何重写URL在ASP.net网站 [英] How to rewrite URL in an ASP.net site

查看:89
本文介绍了如何重写URL在ASP.net网站的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要重写URL在一个asp.net网站

I want to rewrite URL in an asp.net site

我需要的是我不希望用户看到哪种语言的网站创建

What i need is i don't want the user to see in which language the site was created

即它不应该有 www.examplesite.com/index.aspx 为地址

相反,我希望它为 www.examplesite.com/index

我不希望用户看到文件的扩展名

I don't want the user to see the extension of files

如果这个问题是不相关的,请#1重定向这个问题堆叠交换各自的网站。

If this question is not related to Stackoverflow please redirect this question to the respective site of Stack Exchange.

任何帮助是AP preciated。

Any help is appreciated.

推荐答案

您可以在Global.asax文件这样一个简单的级别做到这一点:

You can do this at a simple level in the Global.asax file like this:

Sub Application_BeginRequest(ByVal sender As Object, ByVal e As EventArgs)
    ' Fires at the beginning of each request

    Dim path As String = HttpContext.Current.Request.Path

    If path.ToLower.EndsWith(".aspx") Then
        path = path.Substring(0, path.Length - 5)
        Response.Redirect(path, True)
    Else
        path += ".aspx"
        Context.RewritePath(path)
    End If

End Sub

如果您有要求,如.png文件的其他文件,你可能需要一些额外的逻辑来这些过滤掉。

If you have other files that are requested such as .png files, you may need some additional logic to filter these out.

这篇关于如何重写URL在ASP.net网站的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆