⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 memberlogin.ascx.cs

📁 如果不使用IIS,请先运行 XSP.exe,待提示已侦听 8080端口后
💻 CS
字号:
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using DNNLite.Entites.Modules;
using DNNLite.Comm;
using DNNLite.Entites.Tab;
using System.Collections.Generic;
using Ader.TemplateEngine;

public partial class admin_Member_MemberLogin : TempletPortalModuleBase ,IPostBackEventHandler  
{
    private bool logined = false;
    private string loginmsg = string.Empty;
    protected override string TemplateFile
    {
        get 
        {
            if (logined || Page.User.Identity.IsAuthenticated)
            {
                return Settings.ContainsKey("loginsuccesstpl") ? Settings["loginsuccesstpl"] : "~/Templets/Member/HasLoginS.htm";
            }
            return Settings.ContainsKey("logintpl")? Settings["logintpl"]: "~/Templets/Member/UserLoginS.htm" ; 
        }
    }

    //*****给模板引擎加入数据*********
    protected override void SetValues(IDictionary<string, object> bag)
    {
        bag.Add("eventsource", this.UniqueID );
        bag.Add("loginmsg", loginmsg);
        bag.Add("loginusername", ClientID + "loginusername");
        bag.Add("loginpassword", ClientID + "loginpassword");
        bag.Add("savecookie", ClientID + "savecookie");
        bag.Add("imagecode", ClientID + "imagecode");
        

        if (!string.IsNullOrEmpty(Request[ClientID + "loginusername"]))
            bag.Add("username", Request[ClientID + "loginusername"]);
        else
            bag.Add("username", "");

        if (!string.IsNullOrEmpty(Request["returnurl"]))
        {
            bag.Add("regurl",  Comm.NavigateURL(Comm.PortalInfo.RegisterTabId,
                "returnurl=" + Request["returnurl"])
                );
        }
        else
        {
            bag.Add("regurl", Comm.PortalInfo.RegisterUrl  );
        }

    }

    protected void Page_Load(object sender, EventArgs e)
    {
        
    }

    private void CheckLogin()
    {
        string username = Request[ClientID+ "loginusername"];
        string password = Request[ClientID+"loginpassword"];
        string savecookie = Request[ClientID + "savecookie"];
        string imagecode = Request[ClientID + "imagecode"];

        //****本站登录不要验证码
        //if (imagecode == null || Session["CheckCode"]==null || imagecode.ToUpper() != Session["CheckCode"].ToString().ToUpper())
        //{
        //    loginmsg = "验证码错误!";
        //    return;
        //}

        Session["CheckCode"] = null;

        if (string.IsNullOrEmpty(savecookie))
        {
            savecookie = "0";
        }

        int time = int.Parse(savecookie);

        string returnurl = Request["ReturnUrl"];

        if ( Membership.ValidateUser(username,password ))
        {
            #region 清空除购物车外的所有session
            for (int i = 0; i < Session.Count ; i++)
            {
                if (Session.Keys[i] != "dnnlite_cart")
                {
                    Session[i] = null;
                }
            }
            
            #endregion

            #region 设置身份验证票

            HttpCookie authcookie=
                System.Web.Security.FormsAuthentication.GetAuthCookie(username, false);
            if (time > 0)
            {
                authcookie.Expires = DateTime.Today.AddDays(time);
            }

            Response.Cookies.Add(authcookie);

            #endregion

            logined = true;

            if (!string.IsNullOrEmpty(returnurl))
            {
                Response.Redirect( Server.UrlDecode( returnurl));
            }

            Response.Redirect(Comm.NavigateURL(Tabid), false);
        }
        else
        {
            loginmsg = "登录失败,请重试";
        }
    }

    #region IPostBackEventHandler 成员

    public void RaisePostBackEvent(string eventArgument)
    {
        CheckLogin();
    }

    #endregion





   
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -