2014年6月30日 星期一

ASP.NET Submit (使用POST、GET)

PostDemo.aspx

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="PostDemo.aspx.cs" Inherits="PassValuesBetweenPages.PostDemo" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" method="post" action="PostDemo.aspx?p1=test456">
        <div>
            <input name="test" value="test123" type="text" />
            <input type="submit" value="送出" />    
        </div>
    </form>
</body>
</html>

PostDemo.aspx.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace PassValuesBetweenPages
{
    public partial class PostDemo : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Request.Form["test"] != null)
            {
                string strTest = Request.Form["test"].ToString();
                string strP1 = Request.QueryString["p1"].ToString();
                Response.Write("test : " + strTest);
                Response.Write("p1 : " + strP1);
            }
        }
    }
}

ASP.NET Form Submit (使用POST)

FormSubmit.aspx

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="FormSubmit.aspx.cs" Inherits="PassValuesBetweenPages.FormSubmit" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <script type="text/javascript">
        function submitform() {
            document.forms[0].submit();
        }
    </script>
</head>
<body>
    <form id="form1" method="post" action="FormSubmit.aspx">
        <div>
            <input name="test" value="test123" type="text" />
            <a href="javascript: submitform()">Submit</a>    
        </div>
    </form>
</body>
</html>

FormSubmit.aspx.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace PassValuesBetweenPages
{
    public partial class FormSubmit : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Request.Form["test"] != null)
            {
                string strTest = Request.Form["test"].ToString();
                Response.Write("Form POST : " + strTest);
            }
        }
    }
}

2014年6月25日 星期三

ASP.NET MVC 整合 AD(Active Directory) 登入


先設定Web.config為Windows驗證

如果是Forms與Windows混合驗證,只需將登入畫面設定為Windows驗證,匿名登入可進入另一登入頁面


取得Client AD 帳號方法 HttpContext.Current.User.Identity.Name

若進去網站想要不彈出AD的驗證視窗
1. 安全性 => 近端內部網路 => 網站 => 加入網址
2. 網際網路選項 => 勾選「啟用整合式Windows驗證」

2014年6月20日 星期五

解決LDF檔不斷增大

若系統只靠"完整備份"進行還原,可以用此設定 自動壓縮 True (AUTO_SHRINK ON )

語法:


ALTER DATABASE 資料庫名稱 SET RECOVERY simple
use 資料庫名稱
go
dbcc shrinkfile('資料庫名稱_log',2)
ALTER DATABASE 資料庫名稱 SET RECOVERY FULL

2014年6月13日 星期五

ASP.NET 取得目前所有 Session 清單


HttpContext context = System.Web.HttpContext.Current;
for (int i = 0; i < context.Session.Contents.Count; i++)
  {
    Response.Write(Session.Contents[i].ToString() + "<br />");
  }

2014年6月11日 星期三

Visual Studio 2012 安裝錯誤 Microsoft Web Deploy 3.0 與目前的系統時鐘或簽署檔案的時間戳記核對時...

Visual Stuido 2012 安裝完成後出現如圖錯誤


此錯誤會造成新增 ASP.NET 專案時,發生下面錯誤


解決方式: