当前位置:  编程技术>综合
本页文章导读:
    ▪邮箱激活,注册信息      ----------region.aspx前台------------- <body>     <form id="form1" runat="server">     <div>             <table style="widt.........
    ▪为网站添加安全机制,windows与Form验证。      --------Web.config-------------- <!--基于Windows的身份认证--> <configuration>  <system.web>  <authentication mode="Windows"></authentication>  <authorization>  <!--除了匿名.........
    ▪WebService提供Add和getStudent服务(IIS发布)      -------------WebService1.asmx.cs-----------------  public class WebService1 : System.Web.Services.WebService  {   [WebMethod]  public int Add(int a, int b)  {  return a + b;  }  [WebMethod]  public DataS.........

[1]邮箱激活,注册信息
    来源: 互联网  发布时间: 2013-11-10

----------region.aspx前台-------------
<body>
    <form id="form1" runat="server">
    <div>
   
        <table style="width:50%;">
            <tr>
                <td>
                    用户名:</td>
                <td>
                    <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
                </td>
            </tr>
            <tr>
                <td>
                    用户密码:</td>
                <td>
                    <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
                </td>
            </tr>
            <tr>
                <td>
                    邮箱地址:</td>
                <td>
                    <asp:TextBox ID="TextBox3" runat="server"></asp:TextBox>
                </td>
            </tr>
              <tr>
                <td>
                    <asp:Button ID="Button1" runat="server" Text="注册" onclick="Button1_Click" /></td>
                <td>
                    &nbsp;</td>
            </tr>
        </table>
   
    </div>
    </form>
</body>

--------region.aspx.cs后台-----------------

  public void sendMail(string email, string activeCode,int id)
        {

            MailMessage msg = new MailMessage();

            msg.From = new MailAddress("邮箱详细账号");
            msg.To.Add(email);
            msg.Subject = "请激活注册";

            StringBuilder contentBuilder = new StringBuilder();
            contentBuilder.Append("请单击以下连接完成激活!");
            contentBuilder.Append("<a href='http://localhost:5566/CheckActiveCode.aspx?activecode=" + activeCode + "&id="+id+"'>激活</a>");


            msg.Body = contentBuilder.ToString(); ;

            msg.IsBodyHtml = true;

            SmtpClient client = new SmtpClient();
            client.Host = "smtp.126.com";
            client.Port = 25;

            NetworkCredential credetial = new NetworkCredential();
            credetial.UserName = "@之前的部分";
            credetial.Password = "邮箱密码";

            client.Credentials = credetial;

            client.Send(msg);
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            string userName = this.TextBox1.Text;
            string password = this.TextBox2.Text;
            string email = this.TextBox3.Text;
            string activeCode = Guid.NewGuid().ToString().Substring(0, 8);

            string conStr = ConfigurationManager.ConnectionStrings["conStr"].ConnectionString;
            int number;
            using (SqlConnection con = new SqlConnection(conStr))
            {
                string sql = "insert into T_Users (UserName,Password,Email,Active,ActiveCode) values(@username,@password,@email,@active,@activecode) select @@identity";
                SqlParameter[] prams = new SqlParameter[] {
               
                new SqlParameter("@username",userName),
                new SqlParameter("@password",password),
                new SqlParameter("@email",email),
                new SqlParameter("@active",false),
                new SqlParameter("@activecode",activeCode)
                };
                using (SqlCommand cmd = new SqlCommand(sql, con))
                {
                    con.Open();
                    cmd.Parameters.AddRange(prams);
                    number = Convert.ToInt32(cmd.ExecuteScalar());
                }
            }
            if (number > 0)
            {
                sendMail(email, activeCode,number);
            
                Response.Redirect("regionMessage.aspx");
            }
            else
    

    
[2]为网站添加安全机制,windows与Form验证。
    来源: 互联网  发布时间: 2013-11-10

--------Web.config--------------
<!--基于Windows的身份认证-->
<configuration>
 <system.web>
 <authentication mode="Windows"></authentication>
 <authorization>
 <!--除了匿名之外别人都可以-->
 <deny users="?"/>
<allow users="*"/>
 
<!-- 授权,除了Test这个匿名,别人都可以-->
 <deny users="?"/>
<deny users="Test"/>
 <allow users="*"/>
 </authorization>
 <compilation debug="true" targetFramework="4.0" />
 </system.web>
</configuration>
 

<!--基于Froms的身份认证-->
<configuration>
 <system.web>
 <authentication mode="Forms">
 <!--loginUrl登录时的那个页面(所有的用户都从登录这个页面进入网站,别的地方不让进)
 给Cookie加密protection -->
 
<forms loginUrl="login.aspx" timeout="2880" name="aaa" protection="Encryption"/>
 </authentication>
 <!--授权-->
 <authorization>
 <deny users="?"/>
 <allow users="*"/>
 </authorization>
<compilation debug="true" targetFramework="4.0" />
 </system.web>
 
<!--在images文件夹下的图片是可以被访问的-->
 <location path="images">
 <system.web>
 <authorization>
 <allow users="?"/>
 </authorization>
 </system.web>
 </location>
 
<!--在subPages文件夹下的子页是可以被访问的-->
 <location path="subpages">
 <system.web>
 <authorization>
 <allow users="?"/>
 </authorization>
 </system.web>
 </location>

</configuration>
 

----------registor.aspx-----------
<body>
 <form id="form1" runat="server">
 <div>
 注册页……
 </div>
 </form>
</body>
 
-----------default1.aspx------------
<body>
 <form id="form1" runat="server">
 <div>
 default1页………………
 </div>
 </form>
</body>
 
---------------Login.aspx--------------------
<body>
 <form id="form1" runat="server">
 <div>
 <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
 <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
 <asp:Button ID="Button1" runat="server" Text="Button" Xonclick="Button1_Click" />
 <br />
 <br />
 <img src=/blog_article/"images/1.gif />
 
<br />
 <asp:Login ID="LoginControl" runat="server">
 </asp:Login>
 </div>
 </form>
</body>
 
--------------Login.aspx.cs-----------------------
 protected void Button1_Click(object sender, EventArgs e)
 {
 if (this.TextBox1.Text == "admin" && this.TextBox2.Text == "123")
 {
 //from授权,
 FormsAuthentication.SetAuthCookie(this.TextBox1.Text, false);
 }
 }

作者:liu_111111 发表于2013-1-11 11:53:13 原文链接
阅读:31 评论:0 查看评论

    
[3]WebService提供Add和getStudent服务(IIS发布)
    来源: 互联网  发布时间: 2013-11-10

-------------WebService1.asmx.cs-----------------
 public class WebService1 : System.Web.Services.WebService
 {
 
[WebMethod]
 public int Add(int a, int b)
 {
 return a + b;
 }
 [WebMethod]
 public DataSet GetStudent()
 {
 string constr = ConfigurationManager.ConnectionStrings["studentConstr"].ConnectionString;
 string sql = "select * from student";
 SqlDataAdapter adapter = new SqlDataAdapter(sql, constr);
 DataSet ds = new DataSet();
 adapter.Fill(ds);
 return ds;
 }
 }
==========================Web.config==========================
<configuration>
 <system.web>
 <webServices>
 <protocols>
 <add name="HttpGet"/>
 </protocols>
 </webServices>
 <compilation debug="true" targetFramework="4.0" />
 </system.web>
 <connectionStrings>
 <add name="studentConstr" connectionString="data source=.;initial catalog=student;user

id=sa;password=111111;"/>
 </connectionStrings>
</configuration>
 


-------WebAddStudent.aspx前台---------------
<body>
 <form id="form1" runat="server">
 <div>
 <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
&nbsp;+
 <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
&nbsp;<asp:Button ID="Button1" runat="server" Xonclick="Button1_Click" Text="Button" />
&nbsp;<asp:TextBox ID="TextBox3" runat="server"></asp:TextBox>
 
<br />
 <br />
 <asp:GridView ID="GridView1" runat="server">
 </asp:GridView>
 
</div>
 </form>
</body>
 
-------WebAddStudent.aspx.cs后台------------
 
protected void Button1_Click(object sender, EventArgs e)
 {
 localhost.WebService1 ws=new localhost.WebService1();
 this.TextBox3.Text= ws.Add(Convert.ToInt32(this.TextBox1.Text),Convert.ToInt32
 
(this.TextBox2.Text)).ToString();
 
this.GridView1.DataSource = ws.GetStudent();
 this.GridView1.DataBind();
 }
 

==========================Web.config==========================
<configuration>
 <configSections>
 <sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup,

System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
 <section name="userWebService.Properties.Settings"

type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral,

PublicKeyToken=b77a5c561934e089" requirePermission="false" />
 </sectionGroup>
 </configSections>
 <system.web>
 <compilation debug="true" targetFramework="4.0" />
 </system.web>
 
<applicationSettings>
 <userWebService.Properties.Settings>
 <setting name="userWebService_localhost_WebService1" serializeAs="String">
 <value>http://localhost:1095/WebService1.asmx</value>
 </setting>
 </userWebService.Properties.Settings>
 </applicationSettings>
</configuration>
 

作者:liu_111111 发表于2013-1-11 11:51:49 原文链接
阅读:30 评论:0 查看评论

    
最新技术文章:
▪error while loading shared libraries的解決方法    ▪版本控制的极佳实践    ▪安装多个jdk,多个tomcat版本的冲突问题
▪简单选择排序算法    ▪国外 Android资源大集合 和个人学习android收藏    ▪.NET MVC 给loading数据加 ajax 等待loading效果
▪http代理工作原理(3)    ▪关注细节-TWaver Android    ▪Spring怎样把Bean实例暴露出来?
▪java写入excel2007的操作    ▪http代理工作原理(1)    ▪浅谈三层架构
▪http代理工作原理(2)    ▪解析三层架构……如何分层?    ▪linux PS命令
▪secureMRT Linux命令汉字出现乱码    ▪把C++类成员方法直接作为线程回调函数    ▪weak-and算法原理演示(wand)
▪53个要点提高PHP编程效率    ▪linux僵尸进程    ▪java 序列化到mysql数据库中
▪利用ndk编译ffmpeg    ▪活用CSS巧妙解决超长文本内容显示问题    ▪通过DBMS_RANDOM得到随机
▪CodeSmith 使用教程(8): CodeTemplate对象    ▪android4.0 进程回收机制    ▪仿天猫首页-产品分类
▪从Samples中入门IOS开发(四)------ 基于socket的...    ▪工作趣事 之 重装服务器后的网站不能正常访...    ▪java序列化学习笔记
▪Office 2010下VBA Addressof的应用    ▪一起来学ASP.NET Ajax(二)之初识ASP.NET Ajax    ▪更改CentOS yum 源为163的源
▪ORACLE 常用表达式    ▪记录一下,AS3反射功能的实现方法    ▪u盘文件系统问题
▪java设计模式-观察者模式初探    ▪MANIFEST.MF格式总结    ▪Android 4.2 Wifi Display核心分析 (一)
▪Perl 正则表达式 记忆方法    ▪.NET MVC 给loading数据加 ajax 等待laoding效果    ▪java 类之访问权限
▪extjs在myeclipse提示    ▪xml不提示问题    ▪Android应用程序运行的性能设计
▪sharepoint 2010 自定义列表启用版本记录控制 如...    ▪解决UIScrollView截获touch事件的一个极其简单有...    ▪Chain of Responsibility -- 责任链模式
▪运行skyeye缺少libbfd-2.18.50.0.2.20071001.so问题    ▪sharepoint 2010 使用sharepoint脚本STSNavigate方法实...    ▪让javascript显原型!
▪kohana基本安装配置    ▪MVVM开发模式实例解析    ▪sharepoint 2010 设置pdf文件在浏览器中访问
▪spring+hibernate+事务    ▪MyEclipse中文乱码,编码格式设置,文件编码格...    ▪struts+spring+hibernate用jquery实现数据分页异步加...
▪windows平台c++开发"麻烦"总结    ▪Android Wifi几点    ▪Myeclipse中JDBC连接池的配置
▪优化后的冒泡排序算法    ▪elasticsearch RESTful搜索引擎-(java jest 使用[入门])...    ▪MyEclipse下安装SVN插件SubEclipse的方法
▪100个windows平台C++开发错误之七编程    ▪串口转以太网模块WIZ140SR/WIZ145SR 数据手册(版...    ▪初识XML(三)Schema
▪Deep Copy VS Shallow Copy    ▪iphone游戏开发之cocos2d (七) 自定义精灵类,实...    ▪100个windows平台C++开发错误之八编程
▪C++程序的内存布局    ▪将不确定变为确定系列~Linq的批量操作靠的住...    ▪DIV始终保持在浏览器中央,兼容各浏览器版本
php开源软件 iis7站长之家
▪android Content Provider详解九    ▪简单的图片无缝滚动效果    ▪required artifact is missing.
▪c++编程风格----读书笔记(1)    ▪codeforces round 160    ▪【Visual C++】游戏开发笔记四十 浅墨DirectX教程...
▪【D3D11游戏编程】学习笔记十八:模板缓冲区...    ▪codeforces 70D 动态凸包    ▪c++编程风格----读书笔记(2)
▪Android窗口管理服务WindowManagerService计算Activity...    ▪keytool 错误: java.io.FileNotFoundException: MyAndroidKey....    ▪《HTTP权威指南》读书笔记---缓存
▪markdown    ▪[设计模式]总结    ▪网站用户行为分析在用户市场领域的应用
 


站内导航:


特别声明:169IT网站部分信息来自互联网,如果侵犯您的权利,请及时告知,本站将立即删除!

©2012-2021,,E-mail:www_#163.com(请将#改为@)

浙ICP备11055608号-3