User Control User Login judgment

Source: Internet
Author: User
Using the user control Whelogined.ascx, the code is as follows:
Namespace HEZjs.WebForm.modules.ascx
{
Using System;
Using System.Data;
Using System.Drawing;
Using System.Web;
Using System.Web.UI.WebControls;
Using System.Web.UI.HtmlControls;
<summary>
Summary description of the modwhelogined.
</summary>
public class ModWheLogined:System.Web.UI.UserControl
{
private void Page_Load (object sender, System.EventArgs e)
{
Place user code here to initialize page
String strpath = HEZjs.WebForm.wfFunction.SiteUrl (this. Parent.page) + "modules/aspx/modlogin.aspx";
if (this. session["to page"] = = null)
This. Session.add ("Transfer to Page", this.) PARENT.PAGE.REQUEST.RAWURL);
Else
This. session["Transfer to Page" = this. PARENT.PAGE.REQUEST.RAWURL;
if (this. session["user"]!= null)
{
if ((HEZjs.Sys.sysUser) this. session["User"]). logined)
{
Judging permissions
Specify style
}
Else
{
This. Response.Redirect (strpath);
}
}
Else
This. Response.Redirect (strpath);
}
Code generated #region the Web forms Designer
Override protected void OnInit (EventArgs e)
{
//
CodeGen: This call is required for the ASP.net Web forms Designer.
//
InitializeComponent ();
Base. OnInit (e);
}

<summary>
Designer supports the desired method-do not use the Code Editor
Modify the contents of this method.
</summary>
private void InitializeComponent ()
{
This. Load + = new System.EventHandler (this. Page_Load);
}
#endregion
}
}
Strpath is used to specify the system login interface and the HEZJS.WEBFORM.WFFUNCTION.SITEURL () method is used to return the web address
Session[the address of the page to which the user requests to be placed in the "to page"]
session["User" contains a HEZjs.Sys.sysUser object that includes a logined member to return whether the user is logged in
Drag the user control directly to each page that needs to be logged on, and when the user requests the page, if the user is not logged in, it will go to the login page and, if it is already logged in, normal browsing.
Is it convenient?
You can also make a user's decision about the permissions of the requesting page and the general style of the specified page (if no style is specified beforehand) where the code is labeled.

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.