2013年8月11日 星期日

c# example

font end (html, file name Default.sapx)

Default.sapx

<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" method="post" runat="server">
    <div>
    <asp:TextBox ID="runi" runat="server" Columns="80"></asp:TextBox>
    <asp:Button OnClick="runs" ID="run" Text="Run" runat="server"/>
    </div>
    </form>
</body>
</html>


Back end file name Default.aspx.cs



using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    public void runs(object sender, EventArgs e)
    {
        System.Diagnostics.Process.Start("C:\\Program Files\\Microsoft Visual Studio 8\\SDK\\v2.0\\Bin\\sdkvars.bat");
         System.Diagnostics.ProcessStartInfo sinf1 = new System.Diagnostics.ProcessStartInfo("csc",runi.Text);  
        sinf1.RedirectStandardOutput = true;
        sinf1.UseShellExecute = false;
        sinf1.CreateNoWindow = true;
        System.Diagnostics.Process p1 = new System.Diagnostics.Process();
        p1.StartInfo = sinf1;
        p1.Start();
        string res1 = p1.StandardOutput.ReadToEnd();
        p1.Close();
        Console.WriteLine(res1);
        Console.Read();      
    }
}



web.config
<?xml version="1.0" encoding="utf-8"?>
<configuration xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0">
  <system.web>
    <compilation debug="true" />
  </system.web>
</configuration>



web.config

http://www.codeproject.com/Articles/301726/Web-config-File-ASP-NET


Location of your web.config file is root directory of your website
for ex if u have created mytest website then web.config is created in \mytest\ directory by default.
so location of web.config is \mytest\web.config

Web.config files are stored in XML format which makes us easier to work with.
You can have any number of Web.config files for an application. Each Web.config applies settings to its own directory and all the child directories below it.
All the Web.config files inherit the root Web.config file available at the following locationsystemroot\Microsoft.NET\Framework\versionNumber\CONFIG\Web.config location
IIS is configured in such a way that it prevents the Web.config file access from the browser.
The changes in Web.config don’t require the reboot of the web server.

<configuration>
   <system.web>
      <authentication mode="Forms">
         <forms loginUrl="/login.aspx">
            <credentials passwordFormat="Clear">
               <user
                  name="UserName1"
                  password="PlainTextPassword"/>
            </credentials>
         </forms>
      </authentication>
   </system.web>
</configuration>


Configuring ASP.NET Applications

Visual Studio 2005 Other Versions 3 out of 17 rated this helpful - Rate this topic
Using the features of the ASP.NET configuration system, you can configure an entire server, an ASP.NET application, or individual pages in application subdirectories. You can configure features such as authentication modes, page caching, compiler options, custom errors, debug and trace options, and much more.
The ASP.NET configuration system features an extensible infrastructure that enables you to define configuration settings in XML files that are easily deployed. These files, each named Web.config, can exist in multiple locations in an ASP.NET application. You can add or revise configuration settings at any time with minimal impact on operational Web applications and servers.
For more information about what is new in the .NET Framework version 2.0, see What's New in ASP.NET Configuration.
For more information about configuring .NET Framework client applications, see Configuring Applications and Configuration File Schema for the .NET Framework.
Web.config 檔必須只包含要覆寫 Machine.config 檔中設定的組態項目。Web.config 檔至少必須具有 <configuration> 元素及 <system.web> 元素。這些元素會包含個別組態元素。

下列範例會顯示最小的 Web.config 檔:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <system.web>

  </system.web>
</configuration>


xxxxxxxxxxxx
setting password
xxxxxxxxxxxx


<configuration>
   <system.web>
      <authentication mode="Forms">
         <forms loginUrl="/login.aspx">
            <credentials passwordFormat="SHA1" [Clear | SHA1 | MD5] >
               <user
                  name="UserName1"  [String, Required, Collection Key]
                  password="PlainTextPassword" [String,Required]/>
            </credentials>
         </forms>
      </authentication>
   </system.web>
</configuration>


沒有留言:

張貼留言