[c#]代码库
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
namespace LongGangGlass.Controllers
{
    public class BaseController : Controller
    {
        public bool login
        {
            get
            {
                string username = "";
                try
                {
                    username = Session["username"].ToString();
                }
                catch { }
                if (string.IsNullOrEmpty(username))
                { return false; }
                else
                { return true; }
            }
        }
        public bool UserCheck()
        {
            string username = "";
            string userid = "";
            try
            {
                username = Session["username"].ToString();
                userid = Session["userid"].ToString();
            }
            catch
            { }
            ViewBag.username = username;
            ViewBag.userid = userid;
            if (username == "")
            { return false; }
            else
            { return true; }
        }
        protected void SessinClear()
        {
            Session.RemoveAll();
            Session.Clear();
        }
        public ActionResult AlertAndRedirect(string message, string url)
        {
            return Content("<script>alert('" + Replace(message) + "'); window.top.location.href = '" + url + "';</script>", "text/html");
        }
        public ActionResult Alert(string message)
        {
            return Content("<script>window.alert('" + Replace(message) + "');</script>", "text/html");
        }
        public ActionResult AlertAndRefresh(string message)
        {
            return Content("<script>window.alert('" + Replace(message) + "'); self.location.href = self.location.href;</script>", "text/html");
        }
        public ActionResult Refresh()
        {
            return Content("<script>self.location.href = self.location.href;</script>", "text/html");
        }
        /// <summary>
        /// 替换内容
        /// </summary>
        private static string Replace(string message)
        {
            if (string.IsNullOrEmpty(message)) return string.Empty;
            return message.Replace("'", "\'").Replace("\r\n", "");
        }
    }
}
by: 发表于:2017-12-18 09:38:54 顶(0) | 踩(0) 回复
??
回复评论