redirect in ASP. NET Web Application

Source: Internet
Author: User

In the process of developing ASP. NET MVC Web application, after developing the new system, we need to put the old system's URL redirect the new system

There is a file 301redirectspages.config under the project system directory, which reads as follows:

<Rewritemaps>    <Rewritemapname= "redirects">           <AddKey= "/contact-us.aspx"value= "/contact-us" />        <AddKey= "/services-solutions"value= "/services-and-solutions" />        <AddKey= "/sales-support"value= "/sales-and-support" />        <AddKey= "/events-news"value= "/events-and-news" />        <AddKey= "/services-solutions/services.aspx"value= "/services-and-solutions/services" />        <AddKey= "/services-solutions/solutions.aspx"value= "/services-and-solutions/solutions" />        </Rewritemap></rewritemaps>



In the Web. config file, under System.webserver, there is a rewrite node that appears as follows:
<system.webserver>    <rewriteXdt:transform= "Replace">      <RewritemapsConfigSource= "301redirectspages.config" />      <rules>        <Rulename= "Redirect to HTTPS"stopprocessing= "true">          <MatchURL="(.*)" />          <conditions>            <Addinput= "{HTTPS}"pattern= "^off$" />          </conditions>          <Actiontype= "Redirect"URL= "Https://{http_host}/{r:1}" />        </Rule>        <Rulename= "Remove trailing slash"stopprocessing= "true">          <MatchURL="(.*)/$" />          <conditions>            <Addinput= "{request_filename}"MatchType= "Isfile"negate= "true" />            <Addinput= "{request_filename}"MatchType= "Isdirectory"negate= "true" />          </conditions>          <Actiontype= "Redirect"Redirecttype= "Permanent"URL= "{r:1}" />        </Rule>        <Rulename= "redirects">          <MatchURL=".*" />          <conditions>            <Addinput= "{Redirects:{request_uri}}"pattern="(.+)" />          </conditions>          <Actiontype= "Redirect"URL= "{c:1}"appendquerystring= "true" />        </Rule>      </rules>    </rewrite></system.webserver>

In this case, enter the URL in the browser window:

Localhost/contact-us.aspx will automatically redirect to Localhost/contact-us

Localhost/services-solutions/services.aspx Automatic Redirect to Localhost/services-and-solutions/services

Localhost/services-solutions/solutions.aspx Automatic Redirect to Localhost/services-and-solutions/solutions

However, when you enter

Localhost/services-solutions cannot automatically redirect to Localhost/services-and-solutions

Localhost/sales-support cannot automatically redirect to Localhost/sales-and-support

Localhost/events-news cannot automatically redirect to Localhost/events-and-news

Find a half-day reason to discover that the settings are in Web. config

Appendquerystring= "True" should be changed to appendquerystring= "false"

This is the line <action type= "Redirect" url= "{c:1}" appendquerystring= "true"/>

Should be changed to <action type= "Redirect" url= "{c:1}" appendquerystring= "false"/>

The following Web. config file is changed as follows:

 <rewriteXdt:transform= "Replace">      <RewritemapsConfigSource= "301redirectspages.config" />      <rules>        <Rulename= "Redirect to HTTPS"stopprocessing= "true">          <MatchURL="(.*)" />          <conditions>            <Addinput= "{HTTPS}"pattern= "^off$" />          </conditions>          <Actiontype= "Redirect"URL= "Https://{http_host}/{r:1}" />        </Rule>        <Rulename= "Remove trailing slash"stopprocessing= "true">          <MatchURL="(.*)/$" />          <conditions>            <Addinput= "{request_filename}"MatchType= "Isfile"negate= "true" />            <Addinput= "{request_filename}"MatchType= "Isdirectory"negate= "true" />          </conditions>          <Actiontype= "Redirect"Redirecttype= "Permanent"URL= "{r:1}" />        </Rule>        <Rulename= "redirects">          <MatchURL=".*" />          <conditions>            <Addinput= "{Redirects:{request_uri}}"pattern="(.+)" />          </conditions>          <Actiontype= "Redirect"URL= "{c:1}"appendquerystring= "false" />        </Rule>      </rules>    </rewrite>



redirect in ASP. NET Web Application

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.