asp.net中的窗体身份验证(最简单篇)

《asp.net中的窗体身份验证(验证HTML文件)》源代码 博文《asp.net中的窗体身份验证(验证HTML文件)》中的源代码(http://blog.csdn.net/smallfools/archive/2010/01/07/5148154.aspx) 立即下载

    在创建网站中,常常会使用到身份验证。asp.net中内置了几种身份验证的方式,如Windows、Froms、Passport等。这几种身份验证的方式各有不同。一般来说,网站的身份验证方式都会经过以下几个步骤:

    1、输入用户名和密码,单击确定按钮。

    2、在后台判断用户名和密码是否正确,如果错误返回提示;如果正确,进入可访问的页面。

 

    在ASP时代,通常都会在验证用户名和密码是否匹配之后,创建一个Session,然后在每个需要验证的页面中判断Session是否存在,如果存在,则显示页面内容;如果不存在,产生提示,并跳转到登录页面。

 

    但是,在asp.net时代,这个过程就给大大的减化了,不再需要在每个需要验证的页面中去校验Session,只需要进行如下几步,就可以完成身份验证过程。

 

    第一步:修改web.config文件。

    1、在<system.web>和</system.web>中找到<authentication>节,将其改为“<authentication mode="Forms" />”,其中Forms代表使用表单认证。

    2、<system.web>和</system.web>中添加“<authorization><deny users="?"/></authorization>”,其中“<deny users="?"/>”代表拒绝所有的匿名用户。

 

    第二步:创建login.aspx文件。

    在经过第一步之后,无论用户访问网站中的哪个文件,只要没有经过身份验证,asp.net会自动跳转到login.aspx网页上,并且在URL中使用ReturnUrl参数来传递用户当前访问的网页。

    假设用户没有经过身份验证就直接访问test.aspx文件,那么asp.net会自动跳转了login.aspx网页,此时浏览器窗口中的地址栏中的URL为:“login.aspx?ReturnUrl=%2ftest.aspx”,因此,可以在身份验证通过后,再将网页跳回到ReturnUrl参数指定的网页上去。

 

    第三步:在login.aspx文件中验证身份。

    身份验证方式比较简单,一般都是创建一个文本框和一个密码框,用户输入用户名和密码后,单击提交按钮,则去数据库中验证身份,详细过程就不写了,在此只要输入的用户名为1,密码为2就认为身份验证通过。

    身份验证完毕之后,使用FormsAuthentication.SetAuthCookie()为用户创建一个身份验证的票据,并将其添加到Cookie中。以后,再访问网站中的其他网页,就不需要使用进行身份验证了。单击提交按钮后的代码如下所示。

     

 

    短短三步,就可以进行身份验证,是不是很COOL?

 

=============================

原创不容易,转载请注明出处。

 

 

相关链接:

1、asp.net中的窗体身份验证(最简单篇)

2、asp.net中的窗体身份验证(分目录验证篇)

3、asp.net中的窗体身份验证(完整篇之一:创建asp.net的窗体身份验证方式)

4、asp.net中的窗体身份验证(完整篇之二:asp.net的窗体身份验证过程)

5、asp.net中的窗体身份验证(完整篇之三:用户登录页面)

6、asp.net中的窗体身份验证(完整篇之四:获得用户数据)

7、asp.net中的窗体身份验证(完整篇之五:退出登录)

8、asp.net中的窗体身份验证(完整篇之附录:web.config中相应节点详解)

9、asp.net中的窗体身份验证(不同的角色访问不同的目录)

10、asp.net中的窗体身份验证(验证HTML文件)

11、asp.net中的窗体身份验证(完整篇之六:登出后不能通过后退回来面来的页面)

 

 

 

    本例的下载地址为:http://www.aspxfans.com/myBlogFile/窗体身份验证:最简单篇.rar或http://download.csdn.net/source/1962393

 

    本例在VS2005中测试通过。

    本例的优点是:过程和代码十分简单。

    本例的缺点是:对整个网站都必须要进行身份验证,不能指定哪些文件可以匿名访问,哪些文件不能匿名访问。

 

编写代码实现简单窗体身份验证 编写代码实现窗体身份验证 C# .net 立即下载

相关推荐

【fNIRS可视化学习1】基于NIRS-SPM进行光极可视化并计算通道坐标

设头皮上的目标点为P₀(x₀, y₀, z₀),需要在大脑皮层点集S上找到最合适的投影点P'。

Rose9614的博客 2220

解释:ASP.NET 2.0 中的窗体身份验证

 ASP.NET 2.0 版摘要:本教程阐释 ASP.NET 2.0 版中窗体身份验证的工作机制;阐释 IIS 和 ASP.NET 身份验证如何协作,以及 FormsAuthenticationModule 类的角色与操作。本页内容 目标

诸子百家 1077

C# Socket网络通信UDP(关键字:Socket)

简单Socket-Udp通信 在本文中涉及到通信,仅做简单的通信(服务端接受消息,由客户端发出消息) 如有需要,根据需求可直接copy使用 关键字Socket 需要引用命名空间: using System.Net; using System.Net.Sockets; 服务端: using System; using System.Net; using System.Net.Sockets; u...

MelanceXin的博客 3896

ASP.NET内置的6种验证控件的使用

ASP.NET控件验证 ASP.NET内置的验证控件有以下6种: RequiredFieldValidator控件 CompareValidator控件 RangeValidator控件 RegularExpressionValidator控件 CustomValidator控件 ValidationSummary控件 1、RequiredFieldValidator控件 验证控件用来验证输入文本中的信息内容是否为空 就是在运行网站注册、登陆的时候,需要输入用户名,当你没有输入的时候,判断为空,然后返回一个

weixin_46067990的博客 1万+

三维视觉智能焊接系统:免示教技术的工业应用实践

本文深入探讨了三维视觉智能焊接系统中免示教技术的工业应用实践。该系统通过三维视觉相机实时扫描工件,自动识别焊缝并生成轨迹,将产线换型时间从数小时缩短至几分钟,显著提升了生产柔性。文章详细解析了其核心硬件、算法及工厂部署流程,并展望了与数字孪生、工艺智能化融合的未来趋势。

weixin_29091105的博客 438

S32DS使用手把手教程:从零实现CAN通信配置

深入讲解S32DS使用过程中如何从零开始配置CAN通信,涵盖关键步骤与实用技巧,帮助开发者快速上手S32DS使用中的常见问题与调试方法。

weixin_42405592的博客 1142

ASP.Net 2.0窗体身份验证机制详解(FormsAuthentication)

本篇文章介绍了在ASP.Net 2.0如何做窗体身份验证,并且讲解了IIS和ASP.Net2.0窗体身份验证机制是如何结合在一起的。我们还会详细讲解一下2.0中关于窗体身份验证的一个类:FormsAuthenticationModule。 l 综述 当某一个用户使用用户名成功登陆网站时,FormsAuthentication(窗体身份验证机制,下面统一使用英文术语) 将会创建一个authe...

编程资料大全 424

Xilinx PCIe IP核示例工程仿真流程与关键任务解析

本文详细解析了Xilinx PCIe IP核示例工程的仿真流程与关键任务。通过搭建仿真环境、解读初始化日志,并深入剖析TSK_TX_MEMORY_WRITE_32等核心任务的TLP报文生成与交互过程,帮助开发者掌握PCIe IP核的仿真调试方法,为实际硬件设计提供可靠的验证基础。

weixin_28314575的博客 514

Forms身份验证

IIS 身份验证 ASP.NET 身份验证分为两个步骤。首先,Internet 信息服务 (IIS) 对用户进行身份验证,并创建一个 Windows 令牌来表示该用户。IIS 通过查看 IIS 元数据库设置,确定应该对特定应用程序使用的身份验证模式。如果 IIS 配置为使用匿名身份验证,则为 IUSR_MACHINE 帐户生成一个令牌并用它表示匿名用户。然后,IIS 将该令牌传递给 ...

weixin_34152820的博客 523

从Blender舞步到夜空画卷:基于Pix飞控的无人机编队灯光秀全链路开发实践

本文详细介绍了基于Pixhawk飞控的无人机编队灯光秀全链路开发实践。从Blender三维动画设计、QGroundControl地面站二次开发与MAVLink通信桥接,到PX4飞控的OFFBOARD模式路径控制与LED灯光驱动实现,最后通过Gazebo仿真验证并完成真机组装与首飞。文章为无人机爱好者提供了一套完整的、从创意设计到夜空执行的开源解决方案,重点阐述了多机同步与灯光控制的核心技术挑战与应对策略。

zeta9的博客 596

MOS管基础知识及应用电路Multisim仿真

本文系统介绍了MOS管的基础知识及其在电子电路中的典型应用。首先详细解析了MOS管的基本结构、分类和工作原理,包括NMOS、PMOS及CMOS的特性差异。重点阐述了MOS管的三种放大组态电路(共源、共漏、共栅)及其小信号模型分析。随后通过Multisim仿真验证了MOS管在防反接电路、开关电路、放大电路、逻辑门电路、电平转换电路和开关电源(BUCK、BOOST、BUCK-BOOST)等应用中的实际表现。文章还深入探讨了自给偏压和分压式偏置电路的设计要点。全文通过理论分析与仿真实验相结合的方式,全面展示了MO

XU157303764的博客 1499

Web网络编程第一次试验:ASP.NET4.5标准控件和窗体验证

Web网络编程第一次试验:ASP.NET4.5标准控件和窗体验证前言一、实验目的二、实验环境三、实验内容四、代码及截图五、实验总结 前言 为了帮助同学们完成痛苦的实验课程设计,本作者将其作出的实验结果及代码贴至CSDN中,供同学们学习参考。如有不足或描述不完善之处,敬请各位指出,欢迎各位的斧正! 一、实验目的 1.理解ASP.NET 页面事件处理流程; 2.掌握ASP.NET 标准控件的应用; 3.理解客户端和服务器端验证; 4.掌握ASP.NET各验证控件的使用。 二、实验环境 Visual Studio

sjx3161的博客 3942

基于深度学习DNN LSTM网络的光伏发电量预测 完整代码数据 可直接运行

基于深度学习DNN LSTM网络的光伏发电量预测 完整代码数据 可直接运行

2083

ASP.NET中的窗体身份验证

ASP.NET中的窗体身份验证 摘要:    本教程阐释 ASP.NET 2.0 版中窗体身份验证的工作机制;阐释 IIS 和 ASP.NET 身份验证如何协作,以及 FormsAuthenticationModule 类的角色与操作目标 • 了解 ASP.NET 2

Kill Bill 551

ET2012新版免狗免安装绿色软件

ET2012新版免狗免安祖昂绿色软件。,新界面,新视觉,

jdk-8u144-linux-x64.tar.gz.

该资源为搭建Linux系统Java环境用,资源的后缀为tar.gz格式的压缩包

ASP.Net:基于窗体的身份验证

概述 窗体身份验证使用用户登录到站点时创建的身份验证票,然后在整个站点内跟踪该用户。窗体身份验证票通常包含在一个 Cookie 中。然而,ASP.NET 2.0 版支持无 Cookie 窗体身份验证,结果是将票证传入查询字符串中。 如果用户请求一个需要经过身份验证的访问的页,且该用户以前没有登录过该站点,则该用户重定向到一个配置好的登录页。该登录页提示用户提供凭据(通常是用户名和密码)。然

我生活的点滴 1139

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

ASP.net基于窗体的身份验证

基于窗体的身份验证是 ASP.NET 身份验证服务,它使应用程序能够提供它们自己的登录 UI 和进行它们自己的凭据验证。ASP.NET 验证用户的身份,将未授权的用户重定向到登录页并执行所有必要的 Cookie 管理。这种身份验证是许多 Web 站点使用的流行方法。应用程序必须被配置成使用基于窗体的身份验证,将 设置为 Forms 并且

zhangjian01361的专栏 1002

IDEA的使用指南

IDEA基于java的使用手册,可以最快速的上手,在使用中不断的丰富自己的使用技巧.

ASP.NET基于窗体的身份验证

基于窗体的身份验证是 ASP.NET 身份验证服务,它使应用程序能够提供它们自己的登录 UI 和进行它们自己的凭据验证。ASP.NET 验证用户的身份,将未授权的用户重定向到登录页并执行所有必要的 Cookie 管理。这种身份验证是许多 Web 站点使用的流行方法。 应用程序必须被配置成使用基于窗体的身份验证,将 <authentication> 设置为 Forms 并且拒绝匿名用户...

weixin_33795093的博客 187

asp.net中的窗体身份验证(完整篇之二:asp.net的窗体身份验证过程)

    在《asp.net中的窗体身份验证(完整篇之一:创建asp.net的窗体身份验证方式) 》中介绍了如何通过修改web.config文件来创建窗体身份验证。修改完web.config文件之后,网站就可以使用窗体身份验证方式来验证用户身份了。那么,整个身份验证的过程是怎么样的呢?     前面说过,在asp.net中,身份验证过程分为两部分,一部分是IIS中的身份验证,只有通过了IIS

没有标题,只有问题 4648

ASP.NET 2.0 中的窗体身份验证

目标 • 了解 ASP.NET 2.0 版中窗体身份验证的工作机制。 • 了解窗体身份验证配置如何影响窗体身份验证票的生成。

紫薇星--路在你脚下! 638

ASP.Net 2.0 窗体身份验证机制详解

本篇文章介绍了在ASP.Net 2.0如何做窗体身份验证,并且讲解了IIS和ASP.Net2.0窗体身份验证机制是如何结合在一起的。我们还会详细讲解一下2.0中关于窗体身份验证的一个类:FormsAuthenticationModule。转贴自:http://www.aspxclub.com/ContentView/3689/index.aspx  综述当某一个用户使用用户名成功登陆网

Junelf's BLOG 2129
上一篇: SQL Server日志过大会影响查询结果
下一篇: asp.net中的窗体身份验证(分目录验证篇)
smallfools
博客等级 码龄24年 176粉丝 76原创
评论 3
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值