首页 >> Asp.Net >> 正文
asp.net 学习笔记-ASP.NET
  来源:Dotnet频道 作者:采集 时间:2008-3-31  


  用WSDL命令可以注册web service
  
  在APS.NET中创建WEB服务
  
  以.ASMX扩展名保存文件
  <%@ WebService Language="c#" %>
  using System.Web.Services;
  class TestWS
  {
  [WebMethod]
  public string SayHello(string name)
  {
  return "Hello"+name;
  }
  }
  
  POST 调用Web service
  
  //以下为a.html文件内容
  <form name="f1" method="post" action="http://locallhost/WebServiceTest/Service1.asmx/HelloWorld">
  <input type="test" name="name"><input type="submit">
  </form>
  
  Get 调用Web service
  
  在url中传参
  
  如:
  http://localhost/WebServiceTest/Service1.asmx?op=HelloWorld&name=MyName
  
  将APSX页面修改为用户控件
  
  去除<html> <body> <form>元素
  
  将Web窗体页中ASP.NET指令类型从@Page更改为@Control
  
  更改指令的CodeBehind属性引用以反映.aspx扩展名将更改为 .ascx
  
  将基类从System.Web.UI.Page更改为System.Web.UI.UserControl
  
  在用户控件中,控件的值可以定义属性
  
  有一个用户控件,如果无法访问的话,可以用FindControl方法
  
  变量=((testControl)this.FindControl("tc")).txtUsername;
  //Response.Write(((testControl)this.FindControl("tc")).txtUsername);
  (testControl)是强制类型转换,括号内是类型
  FindControl("tc") tc是控件的name
  .txtUsername是控件的属性
  
  用户控件的使用(在APSX页面中注册)
  <%@ Register TagPrefix="uc1" TagName="menu" Src="menu.ascx" %>
  
  TagPrefix 确定用户控件的唯一命名空间,它将是标记中控件名称的前缀
  
  TagName 为用户控件的名称
  
  Src 用户控件的虚拟路径,例如"UserControl1.ascx"
  
  WEB自定义控件
  
  Web.config
  <!--
  说明:
  
  1.所有的配置都必须被放在<configuration>和</configuration>标记之中.
  
  2.<appSettings>和</appSettings>之间是自定义配置,通常用来自己设置一些常量,Add添加常量,Key是常量的名称,
  value是常量的值.
  <appSettings>
  <add key="con" value="server=.;database=northwind;uid=sa;pwd=;"></add>
  </appSettings>
  
  在程序中可以用System.Configuration.ConfigurationSettings.AppSettings["con"]取值
  SqlConnection con=new SqlConnection(System.Configuration.ConfigurationSettings.AppSettings["con"]);
  con.Open();
  SqlCommand cmd=new SqlCommand("select * from employees",con);
  this.DataGrid1.DataSource=cmd.ExecuteReader();
  this.DataGrid1.DataBind();
  
  3.<system.web>和</system.web>之间的标记是关于整个应用程序的设置.
  如 <pages buffer="true"/> 使用页缓冲
  
  4.<location>和</location>是一个区域标记.Path="aaa"表示下面的设置只对该文件有效.
  -->
  
  customErrors设置(在<system.web>和</system.web>之间)
  
  语法
  <customErrors
  defaultRedirect="url"
  mode="On|Off|RemoteOnly">
  <error statusCode="statuscode" redirect="url"/>
  </customErrors>
  
  身份验证和授权
  
  身份验证类型: WINDOWS 描述: WINDOWS 身份难作为默认的身份验证模式.用于任何形式的IIS身份验证
  
  身份验证类型: FORMS 描述: 基于APS.NET窗体的身份验证作为默认的身份验证模式
  
  身份验证类型: PASSPORT 描述:Microsoft Passport身份验证作为默认的身份验证模式
  
  身份验证类型: NONE 描述: 没有身份验证.用于匿名用户和可以提供其自己的身份验证的应用程序.
  <configuration>
  <system.web>
  <authentication mode="Windows|Forms|Passport|None">?
  <forms name="name" loginUrl="url"
  protection="All|NOne|Encryption"
  timeout="xx" path="/">?
  <credentials passwordFormat="Clear|SHA1|MD5"> /*Clear为明文密码*/
  <user name="用户名" password="密码"/>
  </credentials>
  </forms>?
  <passport redirectUrl="internal"/>?
  </authentication>
  </system.web>
  </configuration>
  
  //基于forms先把IIS中该应用的匿名访问去掉
  
  <forms>标记的属性
  
  属性   选项     描述
  name    None    登录身份验证的Cookie名称
  loginUrl  None    登录页URL.如果没有身份验证Cookie,客户端将被重定向到此URL
  protection ALL     应用程序同时使用数据验证和加密来保护Cookie
  None    加密和验证都禁用
  timeout        一段时间(按分钟计),这段时间之后身份验证Cookie将到期,默认值为30
  path          由应用程序发布的Cookie的路径.默认值是反斜杠(/)
  
  <authentication mode="Forms">
  <forms name="YourCookieName" loginUrl="login.aspx" protection="ALL"></forms>
  </authentication>
  //授权
  <authorization>
  <allow users="?"/>    //<allow users="*"/><!--允许所有用户 -->
  <!--
  <allow users="[逗号分隔的用户列表]"
  roles="[逗号分隔的角色列表]"/>
  <deny users="[逗号分隔的用户列表]"
  roles="[逗号分隔的角色列表]"/>
  -->
  </authorization>
  
  //login.aspx
  
  登录代码
  
  //连接数据库进行验证
  
  if(true)//用户名是否合法
  {
  // System.Web.Security.FormsAuthentication.SetAuthCookie(this.TextBox1.Text,false);//指定的用户名写入到Cookie中(false临时Cookie,true永久Cookie)
  // Response.Redirect("");
  System.Web.Security.FormsAuthentication.RedirectFromLoginPage(this.TextBox1.Text,false);//转到用户原访问的页
  //如果为true,可用System..Web.Security.FormsAuthentication.SignOut();删除,以后又要求登录
  }
  else
  {
  Response.Write("用户不合法");
  }
  
  //如果用户少的话,可以不用数据库,直接允许/拒绝用户
  <authentication mode="Forms"
  <forms name="authCre" loginUrl="login.aspx" protection="ALL">
  <credentials passwordFormat="Clear">
  <user name="aaa" password="aaa"/>
  <user name="bbb" password="bbb"/>
  </credentials>
  </forms>
  </authentication>
  
  登录代码
  
  private void Button1_Click(object sender,System.EventArgs e)
  {
  if(System.Web.Security.FormsAuthentication.Authenticate(this.TextBox1.Text,This.TextBox2.Text)
  {
  //  System.Web.Security.FormsAuthentication.SetAuthCookie(this.TextBox1.Text,true);//此方法需重定向
  //  Response.Redirect("WebForm1.aspx");
  System.Web.Security.FormsAuthentication.RedirectFromLoginPage(this.TextBox1.Text,false);//此方法不需要重定向,直接转到原访问页
  }
  else
  {
  Response.Write("用户不合法");
  }
  }
  //授权时,通配符*表示任何人,?表示匿名


上一篇:Asp.net中服务端控件事件是如何触发的-ASP.NET
下一篇:ASP.Net安装简明手册 -ASP.NET

本篇新闻:asp.net 学习笔记-ASP.NET

相关新闻
相关评论
 
评论表单加载中...
 
Asp.Net文章

 在Visual C++应

 编辑:admin

 时间:2008-3-10


   编程入门网-介绍.NET中的委派(Delegates)之三
   编程入门网-介绍.NET中的委派(Delegates)之二
   编程入门网-介绍.NET中的委派(Delegates)之一
   编程入门网-用Visual C#实现文件下载功能
   编程入门网-用C#写简单的CGI程式
最新文章
   编程入门网-介绍.NET中的委派(Delegates)之三
   编程入门网-介绍.NET中的委派(Delegates)之二
   编程入门网-介绍.NET中的委派(Delegates)之一
   编程入门网-用Visual C#实现文件下载功能
   编程入门网-用C#写简单的CGI程式
总站搜索
搜索
 
热门文章
   oracle数据库文件中的导入\导出
   用Oracle10g列值掩码技术隐藏敏感数据
   VB程序中用ADO对象动态创建数据库和表-VB.NET
   用VB6写简单程序 让电骡自动关机-VB.NET
   使用.NET2.0编写COM组件供VB调用-VB.NET
   VB.NET:键盘控制焦点移动-VB.NET
   用VB.NET绘制GDI图形-VB.NET
   vb.net中应用 ArrayList 实例-VB.NET
 
推荐文章
ASP.NET中的状态管理-ASP.NET
VC、IE、ASP环境下打印、预备的完美解决方案
oracle数据库文件中的导入\导出
VB.NET中快速访问注册表技巧-VB.NET
在vb中实现超连接的方法!和直接发邮件-VB.NET
用VB做realplayer播放列表-VB.NET
在VB.NET中如何实现和利用SortedLists-VB.NET
利用VB.NET Stopwatch对象记录时间-VB.NET
成都古羌科技有限公司版权所有: Copyright@2007-2010 ,ALL Rights Reserved 蜀ICP备07017240号