How to rewrite a URL on ASP.net

I want to rewrite the url on asp.net

What I need, I do not want the user to see in which language the site was created.

ie it should not have www.examplesite.com/index.aspxas the address

instead i want it like www.examplesite.com/index

I do not want the user to see the file extension

If this question is not related to Stackoverflow, redirect this question to the appropriate Stack Exchange site.

Any help is appreciated.

+4
source share
5 answers

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

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 , .

+5

web.config .

<rewrite>
       <rules>
            <clear />

                <rule name="exampleredirect" stopProcessing="true">
                    <match url="^index.aspx" ignoreCase="false" />
                    <conditions logicalGrouping="MatchAll" trackAllCaptures="false" />
                    <action type="Redirect" url="/index" />
                </rule>
        </rules>
</rewrite>

, .

http://forums.asp.net/t/1910607.aspx?web+config+rewrite+rule

+2

, , - URL Rewriting ASP.Net. URL : IIS ASP.NET Web.config.

web.config rewrite <rewrite > </rewrite>.

: .

, .

+2

nuget, URL

0
source

In web.config you need to add a section called <rewrite> </rewrite>, then you have to add the names of the rules / rules, as I did below:

            <rewrite><rules><clear />
               <rule name="redirectrule" stopProcessing="true">
               <match url="^index.aspx" />
               <conditions logicalGrouping="MatchAny" trackAllCaptures="false" />
               <action type="Redirect" url="/index" />
            </rule></rules></rewrite>
0
source

Source: https://habr.com/ru/post/1534204/


All Articles