1.
工具>選項>一般>Web專案
取消勾選 > [在瀏覽器視窗關閉時停止偵錯工具,在偵錯停止時關閉瀏覽器]
2.
工具>選項>一般>偵錯
取消勾選 > [為ASP.NET 啟用JavaScript偵錯(Chrome、Edge 及IE)]
3.
<add key="FileUploadAzureBlob" value="DefaultEndpointsProtocol=https;AccountName={blob_storage_name};AccountKey**********************;EndpointSuffix=core.windows.net" />
<input class="col-md-12" id="inputFile" multiple="" name="files[]" type="file" />
<button class="btn btn-success" id="btnUpload" type="button"> Upload </button>
$(document).on('click', '#btnUpload', function () {
var files = $('#inputFile')[0].files;
//FormData 是Html表單中的 <form >
//此處我們利用建立表單的方式儲存檔案
//之後再透過Ajax的方式,將檔案傳遞到 WebApi 或Controller
var fileData = new FormData();
$.each(files, function (i, o) {
fileData.append(o.name, o); //將檔案"們" Append 進表單
});
if (Object.keys(files).length < 1) {
return; //若input 中沒有檔案,就不使用Ajax
}
$.ajax({
url: '/AzureApi/Upload/',
type: "POST",
contentType: false, // 不設定任何的 Content Header
processData: false, // 不進行資料轉換的步驟
data: fileData, //將檔案放進body中
success: function (result) {
alert('檔案上傳成功');
}
});
});
using Microsoft.WindowsAzure.Storage; //引用
using Microsoft.WindowsAzure.Storage.Blob; //引用
namespace TASSWeb.Controllers.Api
{
public class AzureApiController : BaseApiController
{
[HttpPost]
[Route("AzureApi/Upload/")]
public async Task PostUpload()
{
//FormData Setting
var provider = new MultipartMemoryStreamProvider();
await Request.Content.ReadAsMultipartAsync(provider); //將檔案放進provider內
//Connection String , and Azure Blob Container
string sConnStr = System.Configuration.ConfigurationManager.AppSettings["FileUploadAzureBlob"].ToString();
string sContainer = "filupload"; //需要為小寫英文字母
//建立與Storage的連線以及認證
CloudStorageAccount storageAccount = CloudStorageAccount.Parse(sConnStr);
//連接到Blob Client
CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();
//使用GetBlockBlobReference去取得 CloudBlockBlob 物件的參考
CloudBlockBlob blockBlob = container.GetBlockBlobReference(guFileID.ToString());
//將provider內的資料轉為Stream
Stream filestream = await provider.Files[0].ReadAsStreamAsync();
//檢查容器是否存在,不存在則建立
container.CreateIfNotExists();
try
{
//使用UploadFromStream 將Stream的檔案上傳至Azure Blob Storage 中的Container
//UploadFromStream 或是 UploadFromStreamAsync 這兩種方法 都會已覆蓋的方式上傳檔案
blockBlob.UploadFromStream(filestream);
}
catch (Exception ex){
return Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex.Message);
}
return Request.CreateResponse(HttpStatusCode.OK);
}
}
}
DateTime.Now();
<connectionStrings>
<add name="ConnectionString1" connectionString="Data Source=DatabaseName;Initial Catalog=AdventureWorksLT2008;Persist Security Info=True;User ID=xx;Password=xxxxxxxxx" providerName="System.Data.SqlClient"/>
</connectionStrings>
----------------------------------------------------------------------------------------------------------------------
<div>
<telerik:RadGrid ID="RadGrid1" runat="server" AllowPaging="True" Skin="MetroTouch"></telerik:RadGrid>
<asp:Label ID="Label1" runat="server" Text="Label"/>
</div>
----------------------------------------------------------------------------------------------------------------------
protected void Page_Load(object sender, EventArgs e)
{
//呼叫Function
DataBind_GridView();
}
----------------------------------------------------------------------------------------------------------------------
// Function Start
private void DataBind_GridView() {
//Connection String
string Connection1 = ConfigurationManager.ConnectionStrings["ConnectionString1"].ConnectionString;
string selectDB = "SELECT * FROM SalesLT.Customer";
SqlConnection db = new SqlConnection(Connection1); //new Sql 連線
SqlCommand cmd = new SqlCommand(selectDB, db); //Sql Command
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds);
RadGrid1.DataSource = ds;
}
----------------------------------------------------------------------------------------------------------------------<a href="#id1">Test 錨點</a>
or
<button type="button" onclick="location.href='#id1'">
2.跨頁錨點
<a href='@Url.Action("Action", "Controller")#id1'>
or
<button type="button" onclick="location.href='@Url.Action("Action", "Controller")#id1'">