Difference between revisions of "ASP.Net"
From Bashlinux
(Created page with "__NOTOC__ === 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: ...") |
|||
Line 1: | Line 1: | ||
__NOTOC__ |
__NOTOC__ |
||
=== How to install ASP .Net on IIS and Windows XP Pro === |
=== How to install ASP .Net on IIS and Windows XP Pro === |
||
− | The following steps are necessary to register ASP |
+ | The following steps are necessary to register ASP.Net 2.xxxxx on IIS, which already comes on Windows XP: |
* '''Register ASP .Net ''' |
* '''Register ASP .Net ''' |
||
− | *# Open the command line, go to |
+ | *# Open the command line, go to <code>Start > run</code> and type <code>cmd</code> in the box. |
− | *# Go to |
+ | *# Go to <tt>c:\Windows\Microsoft.Net\framework\v2.xxxxx</tt> folder. |
− | *# Run the command |
+ | *# Run the command <code>aspnet_regiis.exe -i</code> |
* '''Check IIS Setup''' |
* '''Check IIS Setup''' |
||
− | *# Go to |
+ | *# Go to <code>Start > Control Panel > Administrative Tools > Internet Information Services</code> menu. |
− | *# Expand |
+ | *# Expand <tt>local computer</tt> node. |
− | *# Right Click on |
+ | *# Right Click on <tt>Web Sites</tt> folder. |
− | *# On sub-menu click on |
+ | *# On sub-menu click on <tt>Properties</tt>. |
− | *# Click on |
+ | *# Click on <tt>Documents</tt> tab. |
− | *# Ensure |
+ | *# Ensure <tt>Default.aspx</tt> is listed on <tt>Default documents</tt>, if not, then add it. |
*# Restart IIS. |
*# Restart IIS. |
||
Line 19: | Line 19: | ||
Connection string for MS SQL Server from ASP .Net |
Connection string for MS SQL Server from ASP .Net |
||
− | + | * Create a <tt>Connection String</tt> by adding the following code into the <tt><configuration></tt> tags in <tt>web.config</tt> file: |
|
<connectionStrings> |
<connectionStrings> |
||
<add name="MyDbConn" |
<add name="MyDbConn" |
||
Line 26: | Line 26: | ||
</connectionStrings> |
</connectionStrings> |
||
− | + | * Create a <tt>Deafault.aspx</tt> file with the following content: |
|
<%@ Page Language="C#" %> |
<%@ Page Language="C#" %> |
||
<%@ Import Namespace="System.Data" %> |
<%@ Import Namespace="System.Data" %> |
||
<%@ Import Namespace="System.Data.SqlClient" %> |
<%@ 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) { |
||
Line 44: | Line 44: | ||
} |
} |
||
</script> |
</script> |
||
+ | |||
− | |||
<html > |
<html > |
||
<head runat="server"> |
<head runat="server"> |
Latest revision as of 17:17, 9 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
- Open the command line, go to
Start > run
and typecmd
in the box. - Go to c:\Windows\Microsoft.Net\framework\v2.xxxxx folder.
- Run the command
aspnet_regiis.exe -i
- Open the command line, go to
- 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, if not, then add it.
- Restart IIS.
- Go to
How to 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>