ASP.NET 使用笔记

ASP.NET 使用笔记

XML:

读取相对目录下的XML文件:

1、DLL(需要将XML属性加入到工程内部)
System.Reflection.Assembly objAssembly = System.Reflection.Assembly.GetExecutingAssembly();
Stream objStream = objAssembly.GetManifestResourceStream("ProjectName." + strFileName+ ".xml");
XmlDocument m_xmlDocument = new XmlDocument();
m_xmlDocument.Load(objStream);
2、WEB
string strRefFullFileName = System.Web.HttpContext.Current.Server.MapPath(s_strDefaultFileName)
FileStream objFS = File.Open(m_strRefFullFileName , FileMode.OpenOrCreate, FileAccess.Read, FileShare.ReadWrite);
xmlDocument.Load(objFS);

读取XML内容:
<?xml version="1.0" encoding="utf-8" ?>
<Entity name="ObjEmplyeeInfo">
 <SqlString>
  <Sql Name="SearchByEmployeeNo">
   <context>UPDATE Affiliation SET Affiliation.UpdateUserID = @UserID,Affiliation.UpdateDateTime = GETDATE()
    FROM Affiliation INNER JOIN  Person ON Person.PersonID = Affiliation.PersonID
    WHERE Person.EmployeeNo = @EmployeeNo and Affiliation.UpdateDateTime = @UpdateDateTime
   <context>
       <Param Name="@WithdrawDate" attribute="WithdrawDate"/>
   <Param Name="@EmployeeNo" attribute="EmployeeNo" />
   <Param Name="@SequenceNo" attribute="SequenceNo" />
   <Param Name="@UserID" attribute="UserID"/>
   <Param Name="@UpdateDateTime" attribute="UpdateDateTime"/>
  </Sql>
 </SqlString>
</Entity>

代码:
XmlNode xmlNode = m_xmlDocument.SelectSingleNode("Entity/SqlString/Sql[@Name='SearchByEmployeeNo']");
if (xmlNode != null)

 // 内容(<context>)的读取
 String strSql = xmlNode.InnerText.ToString();

 // 其他多个平级节点内容(<Param> 该节点名称可自定义)的读取
 XmlNodeList xmlNodelist = m_xmlDocument.SelectNodes("Entity/SqlString/Sql[@Name='SearchByEmployeeNo']/Param");  
 if (xmlNodelist.Count > 0)
 { 
  string[] strParams = new string[xmlNodelist.Count];
  string[] strValue = new string[xmlNodelist.Count];
  this.m_DataProtoType = new DataProtoType[xmlNodelist.Count];
  for (int i=0; i < xmlNodelist.Count; i++)
  {
   strParams[i] = xmlNodelist.Item(i).Attributes["Name"].Value.ToString();
   strValue[i] = xmlNodelist.Item(i).Attributes["attribute"].Value.ToString();
  }
 }
}


读取web.config上的自定义配置项:
<configuration>
  <configSections>……</configSections>
 <appSettings>
  <add key="isCheckXMLFileUpdateEverWhen" value="true"></add>
 </appSettings>
</configuration>

string str = (string)System.Configuration.ConfigurationSettings.AppSettings["isCheckXMLFileUpdateEverWhen"];


判断文件是否更新
DateTime dtDateTimeLast = File.GetLastWriteTime(m_strFileName);
if (m_dtOldTime.Ticks.CompareTo(dtDateTimeLast .Ticks)!=0){
 ……
}

ASP.NET中调用Script激发按钮click事件
C#
namespace HK_WEB
{
……
 public class ALG_SerchClient : System.Web.UI.Page
 {
  protected System.Web.UI.WebControls.TextBox txtUserID;
  protected System.Web.UI.WebControls.Button btnQuery;
 }
 private void Page_Load(object sender, System.EventArgs e)
 {
  txtUserID.Attributes.Add("onblur","doQuery()");
 }
……
}

ASP.NET
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
  <HEAD>
  <title>MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM<title>
  <script language="javascript">
   document.form1.btnQuery.click();
  </script>
  </HEAD>
 <body MS_POSITIONING="GridLayout">
  <form id="form1" method="post" runat="server">
   <table align="center" width="60%" height="100%" border="0">
    <tr height="5">
     <td width="20%" style="HEIGHT: 26px">
      <asp:TextBox Runat="server" ID="txtUserID" MaxLength style="ime-mode:disabled"></asp:TextBox></td>
     <td width="5%" style="HEIGHT: 26px"><asp:Button Runat="server" ID="btnQuery"></asp:Button></td>
    </tr>
   </table>
  </form>

屏蔽IE回退按钮

 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
  <HEAD>
  <title></title>
  <script language="javascript">
   history.go(1);
  </script>

设置IE缓存过期:
Response.Expires = -1;

反射读取page页面的字段信息
public void test(Page objPageCheck ){
   Type objPageType = objPageCheck.GetType().BaseType;
   FieldInfo objFieldInfo = objPageType.GetField("Field_Name",BindingFlags.Static | BindingFlags.Public);
   if (null != objFieldInfo)
   {
    objPageCheck.Session["Sess_Global_PageCode"] = objFieldInfo.GetValue(objPageCheck);
   }
}

判断程序多启动:
class AA0100
{
        private const string strClassName = "AA0100";
        static int Main(string[] args)
        {
                System.Diagnostics.Process[] objProcess = System.Diagnostics.Process.GetProcessesByName(strClassName);
                if (objProcess.Length > 1)
                {
                        return 1;
                }
                ……
                Return 2;
        }
}
Nunit测试:
[Test]
public void MainTestCase1()
{
        Process objProcess = Process.Start(@"H:/Documents/...../AA0100/bin/Debug/AA0100.exe");
        objProcess.WaitForExit();
        Assert.AreEqual(2, objProcess.ExitCode);
}
[Test]
public void MainTestCase2()
{
        Process objProcess1 = Process.Start(@"H:/Documents/.....//AA0100/bin/Debug/AA0100.exe");
        Thread.Sleep(100);
        Process objProcess2 = Process.Start(@"H:/Documents/.....//AA0100/bin/Debug/AA0100.exe");
        objProcess1.WaitForExit();
        objProcess2.WaitForExit();
        Assert.AreEqual(1, objProcess2.ExitCode);
}
自定义工具
更新页面HTML内容:
1、重写父类方法:
protected override void Render(HtmlTextWriter output)
{      
        output.Write(@"<table border='0' cellpadding='0' cellspacing='0' width='100%' height='1'>
                                <tr>
                                        td height='1' bgcolor='#24377E' width='50%'>
                                                <p><blink><strong>派遣勤務者登録システム</strong></blink>
                                        </td>
                                </tr>
                        </table >”);
}
2、script方法:
页面端代码:
<%@ Control Language="c#" AutoEventWireup="false" Codebehind="MessageBoard.ascx.cs" Inherits="MessageBoard" TargetSchema="
http://schemas.microsoft.com/intellisense/ie5"%>
<FONT face="MS UI Gothic"></FONT>
<div align="center">
        <table border="0" id="AutoNumber1" width="75%" class="Description">
                <%
                        foreach(string strMsg in m_objMessageArrayList)
                        {
                %>
                <tr>
                        <td class="Caution">
                                <p align="center"><FONT face="MS UI Gothic"></FONT><%=strMsg%></p>
                        </td>
                </tr>
                <%
                        }
                %>
        </table>
</div>

配置SQLServer会话状态

态设——SQLServer 模式

1、   在安装有SQLServer的目标服务器上执行sql文件:installsqlstate.sql InstallPersistSqlState.sql。两个脚本均建一个名 ASPState 的数据,它包含若干存储过程。

   两个脚本的差异在于放置 ASPStateTempApplications ASPStateTempSessions 表的位置。InstallSqlState.sql 脚本将些表添加到 TempDB 数据数据算机重新启动时失数据。相反,InstallPersistSqlState.sql 脚本将些表添加到 ASPState 数据数据算机重新启动时保留会数据。
情况下,两个脚本文件均安装在下面的位置
systemroot/Microsoft.NET/Framework/versionNumber

如:C:/WINDOWS/Microsoft.NET/Framework/v1.1.4322目录下

2、   启动服务器上的SQLSERVERAGENT服务。

3、   修改IIS的配置文件web.config

    <sessionState
            mode="SQLServer"
            sqlConnectionString="data source=10.69.0.13;user id=sa;password=sa"
            cookieless="true"
            timeout="20"
    />

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值