asp.net a simple way to rewrite a file as a directory using IIS 404 errors _ Practical Tips

Source: Internet
Author: User
For example: http:/www.jb51.net/8888/
The page is rewritten by http://www.jb51.net/ArticleShow.aspx?id=8888.

Specific implementation methods:
Use IIS's 404 error to implement

"HTTP 404-Files Not found" may be a mistake that you often see and dislike, but good use of this error can give
Web design brings good results, this article is the use of 404来 to achieve a new file.
Specific steps:
1. First set up a page, such as called error.aspx, placed in the root directory of the site, write key code in the Error.aspx
Copy Code code as follows:

public partial class Error:System.Web.UI.Page
{
String Myurl;
int MyPos;
int Myurllen;
String ID;
protected void Page_Load (object sender, EventArgs e)
{
Myurl = Request.Url.ToString ();
MyPos = Myurl.lastindexof ("/") +1;
Myurllen = Myurl.length;
if (MyPos = = Myurllen)
{
Myurl=myurl.remove (MYPOS-1);
MyPos = Myurl.lastindexof ("/") + 1;
Myurllen = Myurl.length;
}
id = myurl.substring (mypos, Myurllen-mypos);
The ID is out here, and the other operation is simple.
The following is based on the ID read the database information, I omitted ....
}
}

2. Modify IIS Custom error messages
Find 404, change the message type to Url,url address is "/error.aspx"
And then it's OK.

Other things to note: I'm not clear yet how efficient this is, compared to other rewrite software I'm not too clear,
Everyone can test and see. We also hope that you can propose a better solution.

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.