帶入複雜型別的參數,來 GET 資料,
以下說明如何用 WebApiContrib 套件來達成這個目的。
1. 透過 NuGet 取得 WebApiContrib 套件。
2. 加上 Using
using WebApiContrib.ModelBinders;3. 於API Controller 加上 attribute
[MvcStyleBinding]4. 加上動作方法
[HttpGet, HttpPost]這樣就可以囉!
using WebApiContrib.ModelBinders;3. 於API Controller 加上 attribute
[MvcStyleBinding]4. 加上動作方法
[HttpGet, HttpPost]這樣就可以囉!
config.EnableCors();Global.asax.cs:
protected void Application_BeginRequest(object sender, EventArgs e)
{
//允許所有的domain
string clientOrigin = HttpContext.Current.Request.Headers["Origin"];
if (!string.IsNullOrEmpty(clientOrigin))
{
HttpContext.Current.Response.AddHeader("Access-Control-Allow-Origin"
, clientOrigin);
}
}
DateTimeNow().ToString("ddd", new System.Globalization.CultureInfo("zh-TW"));
結束。
/// <summary>
/// 將資料套入範本檔
/// </summary>
/// <param name="templateLocation">套表範本路徑(不含檔名)</param>
/// <param name="templateName">套表範本檔名</param>
/// <param name="encoding">語系</param>
/// <param name="model">帶入套表的參數</param>
/// <returns>Html file</returns>
public string MergeTemplate(string templateLocation
, string templateName
, string encoding
, Hashtable model)
{
// 初始化並取得Velocity引擎
VelocityEngine ve = new VelocityEngine();
ve.SetProperty(RuntimeConstants.FILE_RESOURCE_LOADER_PATH
, HttpContext.Current.Request.MapPath(string.Format("~/{0}/"
, templateLocation)));
ve.Init();
Template t = new Template();
// 取得velocity的模版
t = ve.GetTemplate(templateName, encoding);
// 取得velocity的上下文context
VelocityContext context = new VelocityContext(model);
// 輸出流
StringWriter writer = new StringWriter();
// 轉換输出
t.Merge(context, writer);
string r = writer.ToString();
writer.Flush();
writer.Close();
return r;
}
string templateLocation = "vm" //範本檔路徑
string templateName = "temp.html" //範本檔名稱
string encoding = "UTF-8" //編碼
Hashtable model = new Hashtable //參數
model.Add("header", "test header") //「header」是html檔案要套用的參數名稱
//「test header」是參數內的值
VelocityHelper velocityHelper = new VelocityHelper();
string html = velocityHelper.MergeTemplate(templateLocation
, templateName
, encoding
, model);
public class HeaderModel
{
public string text;
public string value;
}
HeaderModel hm=new HeaderModel();
model.Add("header", hm);
$header.text $header.value
<system.web="">
<authentication mode="Forms">
<!--defaultUrl:登入後到哪一頁,loginUrl:使用者未登入的話,要導至哪一頁-->
<forms defaulturl="Default.aspx" loginurl="Login.aspx" timeout="30">
</forms></authentication>
</system.web>
FormsAuthentication.RedirectFromLoginPage("Henry", True);
C#:User.Identity.IsAuthenticated VB:My.User.IsAuthenticated
C#:User.Identity.Name VB:My.User.Name
public class TestObject()
{
string A1;
string A2;
string A3;
}
TestObject testObject = new TestObject();
Type testType = testObject.GetType();
string val = (string) testType.GetField("A2").GetValue(testObject);
testType.GetField("A2").SetValue(testObject, "new value");
網路查到很多都說: 按住電源鍵30秒關機、再同時按住電源鍵+音量上鍵15秒重啟,解決。 實際試過是有效,但某一天看到當配件溫度過高,也是會造成降頻的原因之一, 索性就把電源線拔掉,神奇的事情發生了~~ cpu頻率就正常了 。 但其實當下電源供應器並沒有發熱的現象,只...