Asp.net background to get the file name of the current page
System. Io. Path. getfilename (request. Path). tostring ();
Obtain the file name, parameters, and domain name of the current page.
Suppose the full address of the current page is: http://www.test.com/aaa/bbb.aspx? Id = 5 & name = kelli
"Http: //" is the protocol name.
"Www.test.com" is a domain name
"AAA" is the virtual directory name
"BBB. aspx" is the page name (file name)
"Id = 5 & name = Kelli" is a parameter
[1] obtain the complete URL (protocol name + domain name + virtual directory name + file name + parameter)
String url = request. url. tostring ();
Url = http://www.test.com/aaa/bbb.aspx? Id = 5 & name = kelli
[2] obtain the virtual directory name + Page name + parameter:
String url = request. rawurl;
(Or string url = request. url. pathandquery ;)
Url =/AAA/BBB. aspx? Id = 5 & name = kelli
[3] obtain the virtual directory name + Page name:
String url = httpcontext. Current. Request. url. absolutepath;
(Or string url = httpcontext. Current. Request. Path ;)
Url =/AAA/BBB. aspx
[4] retrieve domain names:
String url = httpcontext. Current. Request. url. Host;
Url = www.test.com
[5] GET parameters:
String url = httpcontext. Current. Request. url. query;
Url =? Id = 5 & name = kelli
Request. querystring ["ID"] and request. querystring ["name"] Access Parameters
Request. urlreferrer can obtain the URL Information of the client's last request, so that we can return the "Previous Page" through this attribute ".
Similarly, request. urlreferrer. query can obtain the relevant parameters of the client's last request URL.
Unified Verification:
Recently I found a good method for unified verification. I wrote it here that I passed the test, but it is not very clear whether it is inappropriate, we also hope to have a high finger.
Create a class file under the appcode folder, inherit the page class, add the page. Load event to the file, and then inherit the class from the file. CS to be verified. Example
Create a class file for basepage_mana.cs:
View plaincopy to clipboardprint?
- Using system. collections;
- Using system. Web;
- Using system. Web. Security;
- Using system. Web. UI;
- Using system. Web. UI. webcontrols;
- Using system. Web. UI. webcontrols. webparts;
- Using system. Web. UI. htmlcontrols;
- Using webutil;
- Using sysmodel;
- Using sysdal;
- /// <Summary>
- /// Let all the background management pages inherit this class, and perform session verification and permission verification here.
- /// </Summary>
- Public class basepage_mana: system. Web. UI. Page
- {
- Public basepage_mana ()
- {
- This. Load + = new eventhandler (thisload );
- //
- // Todo: the verification process is to be completed (todo: a prompt for unfinished work)
- //
- }
- Void thisload (Object sender, eventargs E)
- {
- # The warning verification program needs to be improved (warning is the warning setting)
- If (system. String. isnullorempty (session ["bn_jobnum"] as string ))
- {
- Response. Write ("<MCE: script language = 'javascript '> <! --
- Alert ('Please log in again! '); Parent. Location. href =' ../login_test.aspx ';
- // --> </MCE: SCRIPT> ");
- Response. End ();
- }
- Purviewdal pdal = new purviewdal ();
- String pagename = system. io. path. getfilename (request. path ). tostring (); // I have made a permission judgment class here. I regard the file name as the permission name, so that I can make a unified judgment.
- If (pdal. powercontrol (session ["bn_jobnum"]. tostring (), pagename) = false)
- {
- Response. Write ("<MCE: script language = JavaScript> <! --
- Alert ('You have no permission! '); History. Go (-1 );
- // --> </MCE: SCRIPT> ");
- Response. End ();
- }
- }
- }
Then inherit the class from the file test. aspx.
View plaincopy to clipboardprint?
- Using system;
- Using system. Data;
- Using system. configuration;
- Using system. collections;
- Using system. Web;
- Using system. Web. Security;
- Using system. Web. UI;
- Using system. Web. UI. webcontrols;
- Using system. Web. UI. webcontrols. webparts;
- Using system. Web. UI. htmlcontrols;
- Using system. Collections. Generic;
- Using onlineuser;
- Using sysmodel;
- Using sysdal;
- Using webutil;
- Public partial class test: basepage_do // inherit the class created
- {
- Protected void page_load (Object sender, eventargs E)
- {}
- }