好湿?好紧?好多水好爽自慰,久久久噜久噜久久综合,成人做爰A片免费看黄冈,机机对机机30分钟无遮挡

主頁 > 知識庫 > .net實現網站用戶登錄認證

.net實現網站用戶登錄認證

熱門標簽:400電話辦理哪家性價比高 地圖定位圖標標注 地圖標注的公司有哪些 濮陽外呼電銷系統怎么樣 地圖標注專業團隊 塔城代理外呼系統 代理接電話機器人如何取消 遂寧市地圖標注app 天心智能電銷機器人

cookie登錄后同域名下的網站保持相同的登錄狀態。

登錄

private void SetAuthCookie(string userId, bool createPersistentCookie)
{
  var ticket = new FormsAuthenticationTicket(2, userId, DateTime.Now, DateTime.Now.AddDays(7), true, "", FormsAuthentication.FormsCookiePath);
  string ticketEncrypted = FormsAuthentication.Encrypt(ticket);

  HttpCookie cookie;
  if (createPersistentCookie)//是否在設置的過期時間內一直有效
  {
    cookie = new HttpCookie(FormsAuthentication.FormsCookieName, ticketEncrypted)
    {
      HttpOnly = true,
      Path = FormsAuthentication.FormsCookiePath,
      Secure = FormsAuthentication.RequireSSL,
      Expires = ticket.Expiration,
      Domain = "cnblogs.com"http://這里設置認證的域名,同域名下包括子域名如aa.cnblogs.com或bb.cnblogs.com都保持相同的登錄狀態
    };
  }
  else
  {
    cookie = new HttpCookie(FormsAuthentication.FormsCookieName, ticketEncrypted)
    {
      HttpOnly = true,
      Path = FormsAuthentication.FormsCookiePath,
      Secure = FormsAuthentication.RequireSSL,
      //Expires = ticket.Expiration,//無過期時間的,瀏覽器關閉后失效
      Domain = "cnblogs.com"
    };
  }

  HttpContext.Current.Response.Cookies.Remove(FormsAuthentication.FormsCookieName);
  HttpContext.Current.Response.Cookies.Add(cookie);
}

這樣登錄后,在同域名下的任何頁面都可以得到用戶狀態

判斷用戶是否登錄

public bool IsAuthenticated
{
  get
  {
    bool isPass = System.Web.HttpContext.Current.User.Identity.IsAuthenticated;

    if (!isPass)
      SignOut();

    return isPass;
  }
}

得到當前的用戶名

public string GetCurrentUserId()
{
   return _httpContext.User.Identity.Name;
}

下面給大家一個具體的實例

CS頁代碼:

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.Data.SqlClient;

public partial class Login : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

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

string connString = Convert.ToString(ConfigurationManager.ConnectionStrings["001ConnectionString"]);
//001ConnectionString是我在webconfig里配置的數據庫連接。
SqlConnection conn = new SqlConnection(connString); 
string strsql = "select * from User_table where User_name='" + UserName.Text + "' and Password='" + Password.Text + "'";
SqlCommand cmd = new SqlCommand(strsql, conn);
conn.Open();
SqlDataReader dr = cmd.ExecuteReader(CommandBehavior.CloseConnection);

if (dr.Read())
{ 
Response.Redirect("index.aspx");
conn.Close();
}
else
{
FailureText.Text = "登陸失敗,請檢查登陸信息!";
conn.Close();
Response.Write("script language=javascript>alert('登陸失敗!.');/script>");
}
}

protected void Button2_Click(object sender, EventArgs e) //文本框重置按鈕
{
UserName.Text = "";
Password.Text = "";

}
}

下面是aspx頁面代碼:

%@ Page Language="C#" AutoEventWireup="true" CodeFile="Login.aspx.cs" Inherits="Login" %>

!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" " http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

html xmlns=" http://www.w3.org/1999/xhtml" >
head runat="server">
title>無標題頁/title>
/head>
body>
form id="form1" runat="server"> 
asp:Panel ID="Panel1" runat="server" Height="101px" Width="231px" Wrap="False">
table>
tr>
td align="center" colspan="2">
用戶登陸/td>
/tr>
tr>
td style="width: 89px">
用戶名:/td>
td style="width: 100px">
asp:TextBox ID="UserName" runat="server" Wrap="False">/asp:TextBox>/td>
/tr>
tr>
td style="width: 89px">
密碼:/td>
td style="width: 100px">
asp:TextBox ID="Password" runat="server" TextMode="Password" Width="148px" Wrap="False" >/asp:TextBox>/td>
/tr>
tr>
td align="center" colspan="2" style="text-align: center">
asp:Button ID="Button1" runat="server" Text="登陸" Width="50px" OnClick="Button1_Click" />
asp:Button ID="Button2" runat="server" Text="重置" Width="50px" OnClick="Button2_Click" />/td>
/tr>
tr>
td align="center" colspan="2">
asp:Label ID="FailureText" runat="server" Width="77px">/asp:Label>/td>
/tr>
/table>
/asp:Panel>

/form>
/body>
/html>

您可能感興趣的文章:
  • ASP.NET MVC5網站開發用戶登錄、注銷(五)
  • C#微信公眾號與訂閱號接口開發示例代碼
  • C#微信開發之微信公眾號標簽管理功能
  • C#開發微信公眾號接口開發
  • C#微信公眾號開發之接收事件推送與消息排重的方法
  • C#實現微信公眾號群發消息(解決一天只能發一次的限制)實例分享
  • .NET微信公眾號開發之公眾號消息處理
  • .NET微信公眾號開發之查詢自定義菜單
  • .NET微信公眾號開發之創建自定義菜單
  • .NET C#使用微信公眾號登錄網站

標簽:宜春 本溪 吉林 河南 婁底 重慶 麗江 汕頭

巨人網絡通訊聲明:本文標題《.net實現網站用戶登錄認證》,本文關鍵詞  .net,實現,網站,用戶,登錄,;如發現本文內容存在版權問題,煩請提供相關信息告之我們,我們將及時溝通與處理。本站內容系統采集于網絡,涉及言論、版權與本站無關。
  • 相關文章
  • 下面列出與本文章《.net實現網站用戶登錄認證》相關的同類信息!
  • 本頁收集關于.net實現網站用戶登錄認證的相關信息資訊供網民參考!
  • 推薦文章
    主站蜘蛛池模板: 国产丝袜AV写真福利视频| 老牛影院在线观看| 公与熄bd日本中文字幕2| 男女啪啪高清无遮挡免费直播| 白浆四溢| 性猛交富婆╳XXX乱大交电费 | 男生穿透明内裤见j洗澡图| 男女猛烈啪啪无遮挡激烈| 午夜欧美日韩| 国产成人精品免费久久久久| 国产一级**| 亚洲AV一区二区在线紧身裙教师| 一级做α爱片久久毛片A片| 日韩欧美中字| 高辣浓情_新御宅p018| 中国特黄毛片| 女大学生保姆初体验| 天天爽天天爽| 成人毛片免费观看| 《隔壁放荡人妻BD高清》在线| 69看片色情免费| 疯批+强制+囚禁+多肉+车微博| 欲妇系列小说| 白丝校花??扒开美腿甜美电影| 波罗野结衣被躁57分钟| 久久91精品久久91综合| 色妞色视频一区二区三区四区| 巨胸动漫美女??视频动漫| 特级毛片A级毛片免费播放100 | 国产毛片A级久久久不卡精品| 99ri在线视频网| XXOO好深好爽动态图gfi| 厨房挺进同学熟妇的身体漫画| 被继夫强开小嫩苞小说| 一本在线免费视频| 国产婬妇?????痴汉精品无码| 黄色大片毛片| 女人性药春欲| 好男人www在线观看免费 | 夜夜想夜夜爽天天爱天天摸| 成品短视频网站源码搭建免费 |