日韩黑丝制服一区视频播放|日韩欧美人妻丝袜视频在线观看|九九影院一级蜜桃|亚洲中文在线导航|青草草视频在线观看|婷婷五月色伊人网站|日本一区二区在线|国产AV一二三四区毛片|正在播放久草视频|亚洲色图精品一区

分享

Creating Vanity URLs

 昵稱1519 2005-09-16

Creating Vanity URLs

One interesting feature of the ASP.NET job site is its use of vanity URLs. Each user who registers at the job site is automatically given a personalized home page. For example, if you register with the username marksmith, you can access your home page by going to /aspnetjobs/marksmith.aspx (see Figure 30.4).

Figure 30.4. A vanity URL.

graphics/30fig04.jpg

The vanity URLs are implemented with two files: the Global.asax and UserPage.aspx files. The Global.asax file checks the path of each request made to the job site. When appropriate, the Global.asax file rewrites the path of the request to the UserPage.aspx page. The complete code for the Global.asax file is contained in Listing 30.7.

Listing 30.7 Global.asax
<%@ Import Namespace="System.IO" %>


The C# version of this code can be found on the CD-ROM.

The Global.asax file in Listing 30.7 handles the BeginRequest event that is raised whenever someone requests a page from the job site. When appropriate, the RewritePath method is used to redirect a page request to the UserPage.aspx page.

First, the Application_BeginRequest subroutine checks whether the request is for the Default.aspx page, the Userpage.aspx page, or a page below the /site/ subdirectory. These requests are ignored. You only want to redirect a user when the user makes a request with a vanity URL. You must be careful not to redirect users when they are requesting actual pages at the job site.

NOTE

You also can implement vanity URLs by creating a custom HTTP module. An HTTP module is a class that is executed whenever a request is made for an ASP.NET page. To learn more about creating HTTP modules, see Chapter 15, "Creating ASP.NET Applications."


If the user is not requesting an actual page at the Web site, the RewritePath method is used to redirect the user to the UserPage.aspx page. For example, if the user requests

/aspnetjobs/marksmith.aspx

the Global.asax file automatically rewrites the request like this:

/aspnetjobs/userpage.aspx?pageowner=marksmith

The value of the pageowner query string variable is captured within the UserPage.aspx page. The pageowner variable is used within the UserPage.aspx page to look up and display the information for the appropriate user from the database.

When using the Global.asax file in Listing 30.7, you must be cautious about the physical layout of the files in your Web site. All the actual files for the job site are located beneath the /site/ subdirectory. If you add a new page to the root directory, the page could never be accessed because any requests for the page would be interpreted as a request for a vanity URL. If you need to add new files to the ASP.NET job site, add the new files beneath the /site/ subdirectory.

    本站是提供個人知識管理的網(wǎng)絡(luò)存儲空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點。請注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購買等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請點擊一鍵舉報。
    轉(zhuǎn)藏 分享 獻(xiàn)花(0

    0條評論

    發(fā)表

    請遵守用戶 評論公約

    類似文章 更多