跳到主要內容

發表文章

目前顯示的是有「ASP.NET MVC」標籤的文章

[asp.net] IIS Http/2 cause asp.net MVC Error

最近遇到個怪問題, 所有使用者連線新開發的網站,就有單單有個使用者 開啟網站時 直接出現asp.net 要設定web.config errorModel的錯誤畫面, 就算主機的web.config都設定過一輪 也還是單單他的chrome瀏覽主機會出錯, 仔細想了很多原因都找不到主因 但最後查到可能是chorme執行http/2的連線而asp.net mvc的應用程式執行http1.1連線, 似乎對接不起來,所以試著調整IIS設定 移除http/2的設定 似乎就可以順利連線了 但真的原因是這樣嗎? 說實在的我也很難確定 如何移除IIS http2的設定 方法如下 Discovered two new registry settings for HTTP.SYS in: HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\HTTP\Parameters EnableHttp2Tls   REG_DWORD   0 EnableHttp2Cleartext   REG_DWORD   0

[Azure] asp.net upload file to Azure

Dim connstr As String = String.Format("DefaultEndpointsProtocol=https;AccountName={0};AccountKey={1};", accountName, accountKey) Dim storageAccount As CloudStorageAccount = CloudStorageAccount.Parse(connstr) '//建立 Blob 服務用戶端 '//CloudBlobClient 類別可擷取 Blob 儲存體中儲存的容器和 Blob Dim blobClient As CloudBlobClient = storageAccount.CreateCloudBlobClient() '//依照名稱找尋容器 Dim container As CloudBlobContainer = blobClient.GetContainerReference(containerName) '//如果容器不存在就建立 container.CreateIfNotExists() '//設定容器權限權限 container.SetPermissions(New BlobContainerPermissions With {.PublicAccess = access}) Dim tempF as new HttpPostedFileBase Dim blockBlob As CloudBlockBlob = container.GetBlockBlobReference(tempF.FileName) blockBlob.Properties.ContentType = tempF.ContentType Dim ms As MemoryStream tempF.InputStream.CopyTo(ms) ms.Seek(0, SeekOrigin.Begin) '使用MemoryStream 務必要使用seek 將指標回到起點 blockBlob.UploadFromStream(ms) Dim Url As String = blockBlob.StorageUri....

[ASP.net] ASP.NET Identity使用探討

這一篇寫的很棒 有一個很好的實例,教學如何透過 ASP.NET Identity建立簡易登入機制 http://benfoster.io/blog/aspnet-identity-stripped-bare-mvc-part-1 如果有覺得英文不容易瞭解 建議可以參考以下這篇 https://dotblogs.com.tw/toysboy21/2015/06/11/151546

[MVC] OAuthWebSecurity / WebSecurity 使用者角色(Roles)控管

OAuthWebSecurity / WebSecurity 使用者角色(Roles)控管 使用OAuthWebSecurity / WebSecurity要對登入的使用者設定角色 其實很簡單 只要在註冊程序中加上  Roles.AddUserToRole(UserName, "Role") 如此 該使用者就會有Role的角色 可以用 [Authorize(Roles:="User")]的方式來限定使用者的權限了 當然要使用前 要先建好角色 建立角色的方法如下 Roles.CreateRole("Role")

[Vb.net] asp.net MVC DotNetOpenAuth 串接自有SQLserver

asp.net MVC 提供了DonNetOpenAuth的元件,  讓網站要串接社群網站的SSO變的很容易,  但是直接引用DonNetOpenAuth範例是會自動建立一個mdf檔 就無法使用原本要接的SQL server。  這裡是提供修改範例code的方式 讓DotNetOpenAuth照既定程式, 在SQL server中建立相關的table  1.修改web.config 在web.config中加上SQLserver的連接資訊 [add connectionstring="Data Source=server;Initial Catalog=coolstay;Integrated Security=False;user id=userID;password=password" name="Connection" providername="System.Data.SqlClient"] 2.修改InitializeSimpleMembershipAttribute.vb的連接設定 WebSecurity.InitializeDatabaseConnection("Connection", "UserProfile", "UserId", "UserName", autoCreateTables:=True) 3.修改AccountModels.vb連接設定 Public Sub New() MyBase.New("Connection") End Sub 如此一來 執行系統就會在SQLserver上 建立好相關的table了

[VB.net] Linq Out Join

Dim petOwners = From pers In people Group Join pet In pets On pers Equals pet.Owner Into PetList = Group From pet In PetList.DefaultIfEmpty() Select pers.FirstName, pers.LastName, PetName = If(pet Is Nothing, String.Empty, pet.Name)

動態改變Entities 的資連接料庫/ change Entities connection on run time

使用Entity Framework時,通常一開始就要設定好要連接的資料庫 但如果想要在Run time時 變更連接的資料庫, 就得先設定LazyLoadingEnabled屬性, 讓Entities延遲讀取,在設定連接字串到新的資料庫中 dim MyEntities = New Entities() MyEntities.Configuration.LazyLoadingEnabled = True MyEntities.Database.Connection.ConnectionString = "{New Connection String}"

[JQuery] ajaxfileUpload.js return JSON format Error

在調整asp.net MVC上傳程式的時候, 發現actionresult return JSON時候,會出現下面的錯誤 SyntaxError: Unexpected token < 仔細查了一下,才發現 Retrun回來的JSON,不是單純的JSON資料而已 還被加上了<pre ......的資料 所以回傳回來後javascript接到就認為格式不正確。 主要原因出在ajaxfileupload.js 的一個判斷上 uploadHttpData: function(r, type) { var data = !type; data = type == "xml" || data ? r.responseXML : r.responseText; // If the type is "script", eval it in global context if (type == "script") jQuery.globalEval(data); // Get the JavaScript object, if JSON is used. if (type == "json") eval("data = " + data); // evaluate scripts within html if (type == "html") jQuery("<div>").html(data).evalScripts(); return data; } 只要將原本的 if (type == "json") eval("data = " + data); 修改成 if (type == "json"){ if (data.inde...

[Web] CKeditor blank space at beginning of textareas / Textarea最前面多出空白

用Ckeditor在編輯內容完存入資料庫的時候, 往往會在內容的html前面加上 <p></p> 空行符號 這樣在呈現頁面的時候往往會上畫面上多出一個空白 可以在ckeditor的 config.js中加入以下兩行 config.shiftEnterMode = CKEDITOR.ENTER_BR; config.enterMode = CKEDITOR.ENTER_BR; 就可以解決的這個問題

[MVC] Gen Excel from asp.net MVC

asp.net MVC 要匯出Excel有幾種方式 這邊介紹兩種 1.運用Gridview Dim grid As New GridView() grid.DataSource = srObjList 'obj List or Datatable grid.DataBind() Response.ClearContent() Response.AddHeader("Content-Type", "application/vnd.ms-excel") Response.AddHeader("content-disposition", "attachment; filename=Totalinventory.xls") Response.ContentType = "application/excel" Response.Charset = "big5" Dim sw As New System.IO.StringWriter() Dim htw As New HtmlTextWriter(sw) grid.RenderControl(htw) Response.Write(sw.ToString()) Response.End() return view()   2.使用寫好的view.asp 在controaller中 Response.ClearContent() Response.AddHeader("Content-Type", "application/vnd.ms-excel") Response.AddHeader("content-disposition", "attachment; filename=ExcelFile.xls") Response.ContentType = "application/excel" Response.Charset = "big5" Return View(...

[ASP.net MVC] Declare functions / method in a view

要在asp.net MVC的view中加上function/ method 可以用這個方法<BR> 如果是aspx的view <script runat="server" type="text/VB"> Function fname() As Integer return 1 End Function </script> 若是Razor view @functions{             public bool isEven(int number)             {                 return number % 2 == 0 ? true : false;             }         }  

[ASP.NET MVC]ASP.NET MVC 2.0 upgrade to ASP.NET MVC 4.0

很多人首次接觸ASP.NET MVC 是ASP.NET MVC 2.0 在MVC 2.0的架構下 是無法使用方便的 Razor編輯器 , 如果要自己重新建立一個MVC 3.0的專案也是很麻煩的, 不過有人開發出了一個程式 可以很快的將MVC 2.0的程式升級到MVC 3.0 (不過只限VS2010的專案) Microsoft ASP.NET MVC Solution Converter

[Window] IIS 7.0 update to .net Framework 4.0

IIS 7 預設的 .net Framework 通常是2.0 如果要開發的程式是跑.net Framework 4.0的話 除了先安裝.net Framework 4.0外 IIS 7的設定也要做些調整 設定[站台]的[應用程式集區] 選取要設定的[站台] 選擇[基本設定]出現[編輯設定]的視窗。 在[選取應用程式集區]點選[應用程式集區],下拉選擇[ASP.net v4.0]。 設定[應用程式集區] 選取IIS下面的[應用程式集區] 點選[DefaultAppPool],出現[編輯應用程式集區]視窗 選取.net Framework版本 為 .net Framework v4.0

[.Net] 具有潛在危險 Request.Form 的值 Error

在asp.net開發的時候 如果送出Request.From資料中含有html code 往往會被asp.net的驗證檔下來 這個時候可以在 每個aspx的@page中 加上 validateRequest="false" 的設定 如果是asp.net MVC架構 則可以在function 前宣告 ValidateInput(False) 不過要注意 如.net Framework 4.0以上 則要在Web.config中 [system.web1] 下加入 [httpRuntime requestValidationMode="2.0"/]的設定才可以 相關設定可以參考 MSDN

[vb.net] MVC DropDownList from Enum

in Action     Dim ax = [Enum].GetValues(GetType(EnumType)).Cast(Of  EnumType )().Select(Function(v) New SelectListItem With {.Text = v.ToString(), .Value = CType(v, Integer)})       ViewData("EnumType") = New SelectList(ax, "Value", "Text", "") in view(.aspx) Dim si As SelectList = ViewData("ContenType" %=Html.DropDownList("ContentType", si)

[Asp.net] asp.net MVC 2.0 in Old Version IIS

when you deploye asp.net MVC 2.0 to old version IIS (5.0,6.0) WebSite , you may meet some troubles. 1.IIS don't run on .Net Framework 3.5!! After you FTP / deploye your file to Website, You should copy the all .Net Framework 3.5 DLL file into the "bin" folder in your website. the .Net Framework 3.5 DLL files are in this path C:\Program Files\Reference Assemblies\Microsoft\Framework\v3.5 2. Website didn't install asp.net MVC 2.o You can copy the "System.Web.Mvc.dll" to the "bin" folder System.Web.Mvc.dll in C:\Program Files\Microsoft ASP.NET\ASP.NET MVC 2\Assemblies\System.Web.Mvc.dll 3. Can't not find the VB/VC Complier ,because the Complier version is too old. Because there is a setting in web.config <system.codedom> <compilers> <compiler language="c#;cs;csharp" extension=".cs" warningLevel="4" type="Microsoft.CSharp.CSharpCodeProvider, System, Version=2.0.0.0, Culture...

[.Net] Html.RenderAction/RenderPartial send parameter

Html.RenderAction/RenderPartial can send parameter by routeValues in Global.asax.vb routes.MapRoute( _ "Default", _ "{controller}/{action}/{id}/{parameter}", _ New With {.controller = "Home", .action = "Index", .id = "" , .parameter="" } _ ) in View(.aspx) < %Html.RenderAction("Login", "Member", New With {.id = "1234", .parameter="ABC"})%> <%Html.RenderPartial("Login", "Member", New With {.id = "1234", .parameter="ABC"})%> in Control(.vb) Dim id As String = RouteData.Values("id") Dim parameter As String = RouteData.Values("parameter")