Difference between revisions of "Aspdotnet"

From Bashlinux
Jump to: navigation, search
(talk)
Line 1: Line 1:
 
__NOTOC__
 
__NOTOC__
 
=== How to install ASP .Net on IIS and Windows XP Pro ===
= ASP.Net =
 
== How to install ASP .Net on IIS and Windows XP Pro ==
 
 
The following steps are necessary to register ASP .Net 2.xxxxx on IIS, which already comes on Windows XP:
 
The following steps are necessary to register ASP .Net 2.xxxxx on IIS, which already comes on Windows XP:
   
Line 17: Line 16:
 
*# Restart IIS.
 
*# Restart IIS.
   
== How to connect ASP .Net to MS SQL Server ==
+
=== How to connect ASP .Net to MS SQL Server ===
 
Connection string for MS SQL Server from ASP .Net
 
Connection string for MS SQL Server from ASP .Net
   
 
# Create a ''Connection String'' by adding the following code into the `<configuration>` tags in `web.config` file:
 
# Create a ''Connection String'' by adding the following code into the `<configuration>` tags in `web.config` file:
 
<pre><nowiki>
 
 
<connectionStrings>
 
<connectionStrings>
 
<add name="MyDbConn"
 
<add name="MyDbConn"
Line 28: Line 25:
 
providerName="System.Data.SqlClient" />
 
providerName="System.Data.SqlClient" />
 
</connectionStrings>
 
</connectionStrings>
</nowiki></pre>
 
   
 
# Create a `Deafault.aspx` file with the following content:
 
# Create a `Deafault.aspx` file with the following content:
  +
<%@ Page Language="C#" %>
 
 
<%@ Import Namespace="System.Data" %>
<pre><nowiki>
 
<%@ Page Language="C#" %>
+
<%@ Import Namespace="System.Data.SqlClient" %>
<%@ Import Namespace="System.Data" %>
 
<%@ Import Namespace="System.Data.SqlClient" %>
 
   
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
+
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
   
<script runat="server">
+
<script runat="server">
protected void Page_Load(object sender, EventArgs e) {
+
protected void Page_Load(object sender, EventArgs e) {
 
using (SqlConnection cn = new SqlConnection(ConfigurationManager.ConnectionStrings["MyDbConn"].ToString())) {
 
using (SqlConnection cn = new SqlConnection(ConfigurationManager.ConnectionStrings["MyDbConn"].ToString())) {
 
SqlCommand cmd = new SqlCommand("SELECT COUNT(*) FROM authors", cn);
 
SqlCommand cmd = new SqlCommand("SELECT COUNT(*) FROM authors", cn);
Line 49: Line 43:
 
}
 
}
 
}
 
}
</script>
+
</script>
   
<html >
+
<html >
<head runat="server">
+
<head runat="server">
 
<title>SQL Authentication</title>
 
<title>SQL Authentication</title>
</head>
+
</head>
<body/>
+
<body/>
</html>
+
</html>
</nowiki></pre>
 

Revision as of 21:32, 6 June 2015

How to install ASP .Net on IIS and Windows XP Pro

The following steps are necessary to register ASP .Net 2.xxxxx on IIS, which already comes on Windows XP:

  • Register ASP .Net
    1. Open the command line, go to Start > run and type `cmd` in the box.
    2. Go to `c:\Windows\Microsoft.Net\framework\v2.xxxxx` folder.
    3. Run the command `aspnet_regiis.exe -i`.
  • Check IIS Setup
    1. Go to Start > Control Panel > Administrative Tools > Internet Information Services menu.
    2. Expand local computer node.
    3. Right Click on Web Sites folder.
    4. On sub-menu click on Properties.
    5. Click on Documents tab.
    6. Ensure `Default.aspx` is listed on Default documents, and add it if not listed.
    7. Restart IIS.

How to connect ASP .Net to MS SQL Server

Connection string for MS SQL Server from ASP .Net

  1. Create a Connection String by adding the following code into the `<configuration>` tags in `web.config` file:
<connectionStrings>
  <add name="MyDbConn" 
       connectionString="Server=PC2007\SQLEXPRESS; Database=MyDb; User Id=MyUser; password=MyPass"
       providerName="System.Data.SqlClient" />
</connectionStrings>
  1. Create a `Deafault.aspx` file with the following content:
<%@ Page Language="C#" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SqlClient" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<script runat="server">
  protected void Page_Load(object sender, EventArgs e) {
     using (SqlConnection cn = new SqlConnection(ConfigurationManager.ConnectionStrings["MyDbConn"].ToString())) {
         SqlCommand cmd = new SqlCommand("SELECT COUNT(*) FROM authors", cn);
         cn.Open();
         SqlDataReader rdr = cmd.ExecuteReader(CommandBehavior.CloseConnection);
         rdr.Read();
         Response.Write(rdr[0].ToString()); //read a value
     }
 }
</script>
<html  >
<head runat="server">
   <title>SQL Authentication</title>
</head>
<body/>
</html>