Get the current method asp.net page file name, parameters, such as the domain name. Unified session authentication and permissions verification method ...

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:

  1. using System.Collections;  
  2. using System.Web;  
  3. using System.Web.Security;  
  4. using System.Web.UI;  
  5. using System.Web.UI.WebControls;  
  6. using System.Web.UI.WebControls.WebParts;  
  7. using System.Web.UI.HtmlControls;  
  8. using WebUtil;  
  9. using SysModel;  
  10. using SysDal;  
  11.   
  12. /// <summary>  
  13. /// all Admin pages inherit this class, in session here authentication and permissions verification operation.  
  14. /// </summary>  
  15. public class BasePage_mana : System.Web.UI.Page  
  16. {  
  17.     public BasePage_mana()  
  18.     {  
  19.         this.Load += new EventHandler(thisLoad);  
  20.         //  
  21.         // TODO: verification procedures need to be improved (todo: Tips unfinished work)  
  22.         //  
  23.     }  
  24.     void thisLoad(object sender, EventArgs e)  
  25.     {  
  26. #warning verification procedures need to be improved (warning is a warning settings)  
  27.         if (System.String.IsNullOrEmpty(Session["BN_JobNum"as string))  
  28.         {  
  29.             Response.Write("<mce:script language='javascript'><!--  
  30. Alert ( 'please re-login!' ); parent.location.href = '../login_test.aspx' ;  
  31. // --></mce:script>");  
  32.             Response.End();  
  33.         }  
  34.         PurviewDAL Pdal = new PurviewDAL();  
  35.         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  
  36.         if (Pdal.PowerControl(Session["BN_JobNum"].ToString(), pageName) == false)  
  37.         {  
  38.             Response.Write("<mce:script language=javascript><!--  
  39. Alert ( 'You are not allowed!' ); history.go (-1);  
  40. // --></mce:script>");  
  41.             Response.End();  
  42.         }  
  43.     }  
  44. }  

Then extend this class in the document test.aspx

  1. using System;  
  2. using System.Data;  
  3. using System.Configuration;  
  4. using System.Collections;  
  5. using System.Web;  
  6. using System.Web.Security;  
  7. using System.Web.UI;  
  8. using System.Web.UI.WebControls;  
  9. using System.Web.UI.WebControls.WebParts;  
  10. using System.Web.UI.HtmlControls;  
  11. using System.Collections.Generic;  
  12. using OnlineUser;  
  13. using SysModel;  
  14. using SysDal;  
  15. using WebUtil;  
  16.   
  17. public  partial  class  the Test: BasePage_do // inherit that class created  
  18. {  
  19.     protected void Page_Load(object sender, EventArgs e)  
  20.     {}  

Reproduced in: https: //www.cnblogs.com/zhangchenliang/archive/2011/05/09/2040928.html

Guess you like

Origin blog.csdn.net/weixin_34061555/article/details/93496087