Aspdotnet: Difference between revisions
From Bashlinux
Jump to navigationJump to search
Content deleted Content added
No edit summary |
No edit summary |
||
| Line 4: | Line 4: | ||
* '''Register ASP .Net ''' |
* '''Register ASP .Net ''' |
||
* Open the command line, go to ''Start > run'' and type |
* Open the command line, go to ''Start > run'' and type `cmd` in the box. |
||
* Go to |
* Go to `c:\Windows\Microsoft.Net\framework\v2.xxxxx` folder. |
||
* Run the command |
* Run the command `aspnet_regiis.exe -i`. |
||
* '''Check IIS Setup''' |
* '''Check IIS Setup''' |
||
* Go to ''Start > Control Panel > Administrative Tools > Internet Information Services'' menu. |
* Go to ''Start > Control Panel > Administrative Tools > Internet Information Services'' menu. |
||
| Line 13: | Line 13: | ||
* On sub-menu click on ''Properties''. |
* On sub-menu click on ''Properties''. |
||
* Click on ''Documents'' tab. |
* Click on ''Documents'' tab. |
||
* Ensure |
* Ensure `Default.aspx` is listed on ''Default documents'', and add itt if is not listed. |
||
* Restart IIS. |
* Restart IIS. |
||
== Connect ASP .Net to MS SQL Server == |
|||
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: |
|||
<pre><nowiki> |
|||
<connectionStrings> |
|||
<add name="MyDbConn" |
|||
connectionString="Server=PC2007\SQLEXPRESS; Database=MyDb; User Id=MyUser; password=MyPass" |
|||
providerName="System.Data.SqlClient" /> |
|||
</connectionStrings> |
|||
</nowiki></pre> |
|||
# Create a `Deafault.aspx` file with the following content: |
|||
<pre><nowiki> |
|||
<%@ 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> |
|||
</nowiki></pre> |
|||
Revision as of 08:04, 17 November 2009
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
- Open the command line, go to Start > run and type `cmd` in the box.
- Go to `c:\Windows\Microsoft.Net\framework\v2.xxxxx` folder.
- Run the command `aspnet_regiis.exe -i`.
- Check IIS Setup
- Go to Start > Control Panel > Administrative Tools > Internet Information Services menu.
- Expand local computer node.
- Right Click on Web Sites folder.
- On sub-menu click on Properties.
- Click on Documents tab.
- Ensure `Default.aspx` is listed on Default documents, and add itt if is not listed.
- Restart IIS.
Connect ASP .Net to MS SQL Server
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:
<connectionStrings>
<add name="MyDbConn"
connectionString="Server=PC2007\SQLEXPRESS; Database=MyDb; User Id=MyUser; password=MyPass"
providerName="System.Data.SqlClient" />
</connectionStrings>
- 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>