Karthik N Karthik N - 1 month ago 7
ASP.NET (C#) Question

How to call page name as folder instead of pagename.aspx

I am having pages like

domain.com/about.aspx
domain.com/photos.aspx


But I want like this

domain.com/about
domain.com/photos

Answer

This is known as url re-writing in ASP.NET web forms and can be easily achieved by adding the following code to your Web.config file:

  <system.webServer>
    <rewrite>
      <rules>
        <rule name="RewriteASPX">
          <match url="(.*)" />
          <conditions logicalGrouping="MatchAll">
            <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
            <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
          </conditions>
          <action type="Rewrite" url="{R:1}.aspx" />
        </rule>
      </rules>
    </rewrite>
  </system.webServer>