ASP.net get back the current page file name
System.IO.Path.GetFileName(Request.Path).ToString();
Get the current method page file name, parameters, such as domain name
Suppose the current page full address is: http: //www.test.com/aaa/bbb.aspx id = 5 & name = kelli?
"Http: //" protocol name is
"Www.test.com" is the domain name
"Aaa" is the virtual directory name
"Bbb.aspx" is the page name (file name)
"Id = 5 & name = kelli" parameter
[1] For a complete url (protocol name + name + virtual directory name + file name + parameters)
string url=Request.Url.ToString();
url= http://www.test.com/aaa/bbb.aspx?id=5&name=kelli
[2] Gets the virtual directory name + name + parameters page:
string url=Request.RawUrl;
(或 string url=Request.Url.PathAndQuery;)
url= /aaa/bbb.aspx?id=5&name=kelli
[3] Gets the virtual directory name + Page name:
string url=HttpContext.Current.Request.Url.AbsolutePath;
(或 string url= HttpContext.Current.Request.Path;)
url= /aaa/bbb.aspx
[4] obtain the domain name:
string url=HttpContext.Current.Request.Url.Host;
url= www.test.com
[5] acquisition parameters:
string url= HttpContext.Current.Request.Url.Query;
url= ?id=5&name=kelli
Request.QueryString [ "id"] and Request.QueryString [ "name"] to access the parameters
Request.UrlReferrer url can get information about a client's last request, so that we can return to the "previous" by this property.
Likewise, Request.UrlReferrer.Query portion can obtain the parameters of the client last requested the url.
Unified Authentication:
Recently I discovered a good unified authentication method, write out here, I passed the test, but not very clear there is not the right place, there is still hope master guiding January.
New in appcode folder below a class file, class inheritance page, add page.load events in the file, and then need to be validated .cs files also inherit this class. for example
BasePage_mana.cs a new class file:
- 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>
- /// all Admin pages inherit this class, in session here authentication and permissions verification operation.
- /// </summary>
- public class BasePage_mana : System.Web.UI.Page
- {
- public BasePage_mana()
- {
- this.Load += new EventHandler(thisLoad);
- //
- // TODO: verification procedures need to be improved (todo: Tips unfinished work)
- //
- }
- void thisLoad(object sender, EventArgs e)
- {
- #warning verification procedures need to be improved (warning is a warning settings)
- if (System.String.IsNullOrEmpty(Session["BN_JobNum"] as string))
- {
- Response.Write("<mce:script language='javascript'><!--
- Alert ( 'please re-login!' ); parent.location.href = '../login_test.aspx' ;
- // --></mce:script>");
- Response.End();
- }
- PurviewDAL Pdal = new PurviewDAL();
- String pageName = System.IO.Path.GetFileName (Request.Path) .ToString (); // I'm here to do a right judgment of the class, I put the file name as the name of rights, so that you can achieve a unified judgment
- if (Pdal.PowerControl(Session["BN_JobNum"].ToString(), pageName) == false)
- {
- Response.Write("<mce:script language=javascript><!--
- Alert ( 'You are not allowed!' ); history.go (-1);
- // --></mce:script>");
- Response.End();
- }
- }
- }
Then extend this class in the document test.aspx
- 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 the Test: BasePage_do // inherit that class created
- {
- protected void Page_Load(object sender, EventArgs e)
- {}
- }
Reproduced in: https: //www.cnblogs.com/zhangchenliang/archive/2011/05/09/2040928.html