1, through an example to introduce the library permissions, which involves the application of the database, in Visual Studio 2010 connected to the database to create datasets and data tables may be unable to remotely connect errors, the specific IDE solution
 
can refer to SQL Server 2008 R2:error 26 to open the remote connection detailed
2, this example, by entering the user name and password to determine whether the user is a regular user or charge users, and then enter the download picture list, non-user click to download is to go to jump page prompts, ordinary users download pictures are with watermarks
 
Try the picture, while the user downloading the picture is the original version of the picture. At the time of landing, set the error landing times limit and try to log in time interval requirements.
 
This process requires setting up data tables and datasets: Build a Dal folder where the dataset is stored in the App_date folder to ensure data security
 
The data table is as follows:
 
 
The database statements are as follows:
 
SELECT ID, sUserName, Spassword, Ilevel, Serrortime, slasterrortime from T_userinfo
 
SELECT ID, Ilevel, Serrortime, Slasterrortime, Spassword, sUserName from T_userinfo WHERE (ID = @ID)
 
SELECT ID, Ilevel, Serrortime, Slasterrortime, Spassword, sUserName from T_userinfo WHERE (susername = @sUserName)
 
UPDATE t_userinfo Set serrortime=isnull (serrortime,0) +1,slasterrortime=getdate () where id= @ID
 
UPDATE t_userinfo Set serrortime=0 where id= @ID
 
Landing page: Login.aspx
 
 
  
  Copy Code code as follows: 
 
 
  
 
 <%@ Page language= "C #" autoeventwireup= "true" codefile= "Login.aspx.cs" inherits= "Picture downloads. Login"%> 
 
 
  
 
 <! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
  
 <title></title>
<body>
<form id= "Form1" runat= "Server" >
<div>
</div>
<asp:label id= "Label1" runat= "server" text= "Username:" ></asp:Label>
<asp:textbox id= "txtUserName" runat= "Server" ></asp:TextBox>
<asp:label id= "Lablwarn" runat= "Server" backcolor= "#FF3300"
Bordercolor= "#FF3300" visible= "False" ></asp:Label>
<br/>
<asp:label id= "Label2" runat= "server" text= "Password:" ></asp:Label>
<asp:textbox id= "Txtpassword" runat= "Server" textmode= "Password" ></asp:TextBox>
<br/>
<br/>
<asp:button id= "Btnlogin" runat= "Server" onclick= "Btnlogin_click" text= "Landing"/>
</form>
</body>
 
  
 
Landing page: Login.aspx.cs
 
 
  
  Copy Code code as follows: 
 
 
  
 
 Using System; 
 
Using System.Collections.Generic; 
 
Using System.Linq; 
 
Using System.Web; 
 
Using System.Web.UI; 
 
Using System.Web.UI.WebControls; 
 
Using a picture download. DAL. Datasetpictableadapters; 
 
 
  
 
 namespace Picture Download
{
public partial class Login:System.Web.UI.Page
{
protected void Page_Load (object sender, EventArgs e)
{
  
 
 }
  
 protected void Btnlogin_click (object sender, EventArgs e)
{
T_userinfotableadapter adapter = new T_userinfotableadapter ();
var data = adapter. Getdatabyusername (txtUsername.Text);
if (data. Count <= 0)
{
Lablwarn. Text = "User name does not exist";
Lablwarn. Visible = true;
}
else {
A single method of LINQ, returned as a data
Data is 0 or more, throw an exception, kill the bug in the cradle
var user = data. Single ();
 
 
                 //Determine if error times and errors are empty 
                // Calculates the current time and the last error-minute difference 
                 if (!user. Isserrortimenull () &&!user. Isslasterrortimenull ()) {
                      Double time = (datetime.now-user.slasterrortime). Totalminutes; 
                      if (Time <= && user.serrortime > 5) 
         & nbsp;           {
  
 
                           Lablwarn. Text = "Enter password error too many times, please wait 30 minutes and re-enter"; 
                          Lablwarn. Visible = true; 
                          return; 
                     } 
                } 
  
 
 if (User.spassword = = txtPassword.Text)
{
session["Whether to log in" = true;
session["Login ID"] = user.id;
  
 Lablwarn. Text = "Landing success, welcome back";
Lablwarn. Visible = true;
Number of empty errors
Adapter. Reserttimebyid (user.id);
Context.Response.Redirect ("pic_list.htm");
Then redirect to other pages
}
else {
Adapter. Incerrortimebyid (user.id);
Lablwarn. Text = "Password error, please re-enter";
Lablwarn. Visible = true;
}
}
}
 
 
 }
}
/* ERROR: Network-related or instance-specific error occurred while establishing a connection with SQL Server.
* The server was not found or could not be accessed. Please verify that the instance name is correct and that SQL Server is configured to allow remote connections.
* (Provider:sql network interfaces, error:26-error locating the specified server/instance)
*
Solution
*/
  
  
Download List page: pic_list.htm 
 
<a href= "pic_download.ashx?filename=11.jpg" > Pictures 1</a>
<a href= "pic_download.ashx?filename=11.jpg" > Pictures 2</a>
<a href= "pic_download.ashx?filename=11.jpg" > Pictures 3</a>
 
Download List page: pic_download.ashx
Using System.Linq;
Using System.Web;
Using a picture download. DAL. Datasetpictableadapters;
Using System.Web.SessionState;
Using System.Drawing;
 
 Namespace Picture Download 
 {
    ///<summary> 
    ///pic_download Summary Description 
    ///</summary> 
     public class Pic_download:ihttphandler, IRequiresSessionState 
     {
 
         public void ProcessRequest (HttpContext context) 
          {
             if ( Context. session["Login"] = = null) 
             {
                  context. Response.Redirect ("target.htm"); 
            } 
             else {
                  string fileName = context. request["FileName"]; 
 
                //Header 
                  context. Response.contenttype= "Image/jpeg"; 
                 String NewFileName = Httputility.urlencode (fileName); 
                 context. Response.AddHeader ("Content-disposition", "attachment:filename=" + newfilename); 
 
Get Data from ID
int user_id = (int) context. session["Login ID"];
T_userinfotableadapter adapter = new T_userinfotableadapter ();
var data = adapter. Getdatabyid (USER_ID);
var user = data. Single ();
 
if (user.ilevel = 0)//normal user
{
using (System.Drawing.Bitmap bitimage = new System.Drawing.Bitmap ("image/" + fileName)
{
Set Canvas
using (System.Drawing.Graphics g = System.Drawing.Graphics.FromImage (Bitimage))
{
g.DrawString ("Free user trial--" +user.susername, New System.Drawing.Font ("XXFarEastFont-Arial"), brushes.red, 0, 0);
}
Save to the output stream
Bitimage.save (context. Response.outputstream, System.Drawing.Imaging.ImageFormat.Jpeg);
 
                     } 
                } 
                 else//fee users 
                 {
                      context. Response.WriteFile ("image/" +filename); 
                } 
            } 
        } 
 
public bool IsReusable
{
Get
{
return false;
}
}
}
}
Jump page: target.htm
 
 
  
  Copy Code code as follows: 
 
 
  
 
 
<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd "> 
 
<title> Jump </title> 
 
<body> 
 
Please log in first, the page will be 5 seconds after the landing page, if 
 
You want to enter the login interface immediately, please <a href= "Login.aspx" > click here </a> 
 
<br/> left <div id= "Leftdiv" ></div> sec 
 
</body> 
 
<script type= "Text/javascript" > 
 
var leftsecond = 5; 
 
SetInterval (function () { 
 
if (leftsecond <= 0) { 
 
Window.location.href = "Login.aspx"; 
 
} 
 
document.getElementById ("Leftdiv"). InnerHTML = Leftsecond; 
 
leftsecond--; 
 
}, 1000) 
 
</script> 
 
 
 
 
Summary: 
 
(1, the biggest problem is to encounter the problem of remote connection to the database, but understand that SQL Server 2008 does not default support, you need some setup, specific process: SQL Server 2008 r2:error 26 Open remote Connection detailed
Detailed source reference: SQL Server 2008 r2:error 26 Open remote Connection detailed
(2, get the context.) Request and so on need to resolve IRequiresSessionState interface