web.config是写在xml文件中的用于记录asp.netweb应用程序的配置信息,它与身份验证是web B/S的基础内容,本文通过对北大青鸟视频的观看,讨论一下对两者的基本认识。
<configuration> <configSections> <!--声明区--> </configSections> <!--执行区 --> <system.web> <!--允许调试--> <compilation debug="true" targetFramework="4.0" /> <!--buffer 缓冲客户端响应 enableViewState设置视图状态--> <pages buffer ="true" enableViewState ="false"> </pages> </system.web> </configuration>
<system.web> <!--发生错误页面时跳转到友好界面 mode为页面文件指示,on开启,off关闭,remoteonly只展示给长途计算机 --> <customErrors defaultRedirect ="default.aspx" mode ="RemoteOnly"> <error statusCode ="404" redirect ="error.aspx"/> </customErrors> </system.web>自定义配置,通过调用key值使用value内容实现配置内容:
<appSettings> <add key ="con" value ="database=.;……"/> </appSettings>
<authentication name="authWeb" loginUrl="login.aspx" protection="all" timout="20"></authentication> <!--name:身份验证的Cookies名称 loginUrl:登录页URL,没有cookie验证则跳转到login.aspx protectiong="All"同时使用数据验证和加密来保护cookie timeout:一段时间后cookie到期 --> <authorization> <allow user="*"/><!--允许通过的用户--> <deny users="?"/> </authorization>
System.web.Security.FormsAuthntication.SetAuthCookie(this.TextBox1.text,false); //制定用户名写到cookies中,建立永久cookies System.FormsAuthentication.RedirectLoginPage(this.TextBox1.Text,false); //写入,转入上一个请求页