简体   繁体   中英

asp.net make virtual directory on database entry

I have a URL foo.com/page.aspx?id=1 and the ID is equal to a record in the database.

I would like the website to create a virtual directory as foo.com/1/ and have it display the same thing after the record is created in the database.

How do I create a virtual directory or is there a way to translate it on the server?

I would recommend the IIS url rewrite module . That way the page request foo.com/1 is translated to foo.com/page.aspx?id=1 .

<rewrite>
  <rules>
    <rule name="pages" stopProcessing="true">
      <match url="^([0-9/]+)" ignoreCase="true"/>
      <action type="Rewrite" url="page.aspx?id={R:1}"/>
    </rule>
  </rules>
</rewrite>

Then you can just fetch the id with string id = Request.QueryString["id"].ToString(); on page.aspx and show the corresponding contents from the database.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM