1. 求C# MVC4 做的上傳附件下載附件的功能 附件路徑存在資料庫中 附件存在項目下的uploading文件中 求源碼
建議使用uploadfy插件,但有一點,配置文件里銀鄭得改,不然不能余搏局上豎讓傳大文件
下載在Controller里返回FileStreamResult就行了
return File(new FileStream(fullPath, FileMode.Open), "application/octet-stream", Server.UrlEncode(Path.GetFileName(fullPath)));
2. 如何調試MVC4的代碼
下載了 http //aspnetwebstack codeplex com/SourceControl/list/changesets 這上面
.NET 4.0 RTM的源碼,
裝了一個git,然後下載就可以了
git clone https //git01 codeplex com/aspnetwebstack.git
時間稍微長了點兒,半個小時吧;
然後裡面src全是MVC4的源碼(其實很大一部分都在裡面了)
解決反感是runtime.sln的,打開之後,在裡面新建一個MVC4的項目,
這里有個問題,我下載的MVC4,在
system.web.mvc項目里Properties\CommonAssembley.cs里,全是5.0.0.0的版本號,
我把他改成了5.0.0.1
#if
ASPNETMVC [assembly: AssemblyVersion("5.0.0.1")] [assembly:
AssemblyFileVersion("5.0.0.1")] [assembly: AssemblyProct("Microsoft ASP.NET
MVC")] #elif ASPNETWEBPAGES
然後修改根目錄下的 web.config
<appSettings>
<add
key="webpages:Version" value="3.0.0.0" />
<add key="webpages:Enabled" value="false" />
<add key="PreserveLoginUrl" value="true" />
<add key="ClientValidationEnabled" value="true" />
<add key="UnobtrusiveJavaScriptEnabled" value="核慶true" />
</appSettings>
這里之所以改成3.0.0.0的原因,是因為在我下載的源碼里,他的者氏州版本號首蔽就是3.0,
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Web.Helpers"
publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="1.0.0.0-2.0.0.0"
newVersion="3.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Web.Mvc"
publicKeyToken="31bf3856ad364e35" />
<bindingRedirect
oldVersion="1.0.0.0-4.0.0.0" newVersion="5.0.0.1" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Web.WebPages"
publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="1.0.0.0-2.0.0.0"
newVersion="3.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="EntityFramework"
publicKeyToken="b77a5c561934e089" />
<bindingRedirect oldVersion="1.0.0.0-5.0.0.0"
newVersion="5.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="WebGrease"
publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="1.0.0.0-1.3.0.0"
newVersion="1.3.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime> 這里的改成了我自己的版本號
然後修改view下面的web.config
<configSections>
<sectionGroup name="system.web.webPages.razor"
type="System.Web.WebPages.Razor.Configuration.RazorWebSectionGroup,
System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral,
PublicKeyToken=31BF3856AD364E35">
<section name="host"
type="System.Web.WebPages.Razor.Configuration.HostSection,
System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral,
PublicKeyToken=31BF3856AD364E35" requirePermission="false" />
<section name="pages"
type="System.Web.WebPages.Razor.Configuration.RazorPagesSection,
System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral,
PublicKeyToken=31BF3856AD364E35" requirePermission="false" />
</sectionGroup>
</configSections>
這里修改成了3.0,當然具體是什麼,看你自己下載的,但是我覺得大部分應該跟我的是一樣的(環境VS2012,源碼4.0 RTM)
<system.web.webPages.razor>
<host factoryType="System.Web.Mvc.MvcWebRazorHostFactory,
System.Web.Mvc, Version=5.0.0.1,
Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<pages pageBaseType="System.Web.Mvc.WebViewPage">
<namespaces>
<pages
validateRequest="false"
pageParserFilterType="System.Web.Mvc.ViewTypeParserFilter,
System.Web.Mvc, Version=5.0.0.1,
Culture=neutral, PublicKeyToken=31BF3856AD364E35"
pageBaseType="System.Web.Mvc.ViewPage, System.Web.Mvc,
Version=5.0.0.1, Culture=neutral,
PublicKeyToken=31BF3856AD364E35"
userControlBaseType="System.Web.Mvc.ViewUserControl, System.Web.Mvc,
Version=5.0.0.1,
Culture=neutral,
PublicKeyToken=31BF3856AD364E35">
同樣,修改之(具體是不是不修改也成,我就不知道了,我是按照網上的方法改的,最後的地方,會給出連接大家注意學習吧)
這樣,配置文件和MVC代碼中的版本號,就修改完了,
然後打開VS2012的命令行,執行
Run
"sn.exe -Vr *,31BF3856AD364E35" in the Visual Command line (哈哈,你看,我真的是COPY的,原創的東西幾乎沒有)
然後把項目中的system.web.mvc的引用,改到你的MVC4的源碼里的項目,當然,不止這一個,不然會有很多地方報錯的,大致的DLL有 :
system.web.razot; system.web.webpages;system.web.webpages.deployment;
system.web.webpages.razor; 這里不全沒關系,網頁上會明確提示少哪個的.
如果出現了一個類型轉換的錯誤:
用戶代碼未處理
System.InvalidCastException
HResult=-2147467262
Message=[A]System.Web.WebPages.Razor.Configuration.HostSection 無法強制轉換為
[B]System.Web.WebPages.Razor.Configuration.HostSection。類型 A
源自「System.Web.WebPages.Razor, Version=2.0.0.0, Culture=neutral,
PublicKeyToken=31bf3856ad364e35」(在上下文「Default」中的「C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Web.WebPages.Razor\v4.0_2.0.0.0__31bf3856ad364e35\System.Web.WebPages.Razor.dll」位置處)。類型
B 源自「System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral,
PublicKeyToken=31bf3856ad364e35」(在上下文「Default」中的「C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary
ASP.NET
Files\root\49f25bf0\9ce908d5\assembly\dl3\70f2ab4b\b0630cdc_834fce01\System.Web.WebPages.Razor.dll」位置處)。
Source=System.Web.WebPages.Razor
這個錯誤,就是我為什麼要該system.web.webpages的版本好的原因了; 如果出現其他DLL,大家也可以隨著改一下;
之後,就可以在頁面中隨便加空間,就能看到斷點的執行了,好運;
當然,網上還有個傢伙說不用修改源代碼,但是要下載SkipStrongNames的一個東西,但是我點了連接,提示我下載已經移除了,不知道怎麼回事,要是有搞定了的同學,也請通知我下哈,學習學習;
3. 怎麼調試mvc5 源碼,怎麼附加mvc5 源碼
1、目前MVC源碼版本為5.2.3,下回來後用VS2013打開,把System.Web.Mvc項目的版本號改為4.0.0.1
2、在解決方案下建一個MVC4項目,.NET選4.5,修改根目錄以及Views下的Web.Config:
把Mvc版本改為4.0.0.1,把Razor,WebPages等改為3.0.0.0,總之,要把Web.Config涉及到:
System.Web.Mvc
System.Web.Razor
System.Web.WebPages
System.Web.WebPages.Deployment
System.Web.WebPages.Razor
這引引用的,把版本號改為跟MVC源碼項目中一致。
3、刪掉引用:
將這些引用改為引用相應的項目
4、運行:sn.exe -VR *,31bf3856ad364e35
4. asp.net mvc4發布到iis7.0,訪問不正常。
看你這個link和script標簽中的字元串。應該用的是BundleConfig來配置樣式表和腳本。那麼出現這種情況就有兩種可能。第一種可能的確是和Layout沒有載入到有關。第二種是BundleConfig中的寫法錯誤(也有可能發布的時候樣式表和腳本文件沒有一起發布,不過這種可能性比較小,此處忽略)。解決方案如下:
對於第一種情況,載入不到的原因可能是:你用了區域Areas。沒有指定全局Layout,也沒有指定局部Layout那麼當然載入不到。你只要在每個cshtml文件的開頭都用
Layout="~/Layout路徑";
這種形式指定。這樣就解決了。
對於第二種。稍微復雜。在BundleConfig中檔中返你肯定用到了如下的寫法:
bundles.Add(newStyleBundle("~/Content/css").Include("~/Content/site.css"));
這里你要注意,默認情況下,BundleConfig的忽略規則會無視壓縮行飢文件,比如
bundles.Add(newStyleBundle("~/Content/css").Include("~/Content/site.min.css"));
這個路徑裡面帶有「min」。會被認為是壓縮過的樣式文件。直接忽略。關於壓縮的事情建議你搜索一下,關鍵字直接就用「BundleConfig」就行了。一大堆。你試試把min去掉或許就行了。
還有一點。還是這個文件路徑的問題。你看這個StyleBundle或者ScriptBundle裡面的字元串。必須要和你文件的路徑吻合。比如:
bundles.Add(newStyleBundle("~/Content/themes/base/css").Include(
培裂"~/Content/themes/base/jquery-ui.css"));
關於/Content/themes/base/css這裡面的最後一個css。這個好像是可以自定義的。我以前研究過mvc4源代碼。現在忘記掉了。你可以自己去試試。或者也去看看源代碼。
至於include中的路徑就更不用說了必須要寫相對路徑。
就是這樣了。
5. 請教,MVC4怎樣才能讓cshtml也編譯到DLL,使源代碼不可見
解決方法
請教,MVC4怎樣才能讓cshtml也編譯到DLL,使源代碼不可見,吵斗棗最好是能刪除cshtml文件,也能正常銷巧使用,有沒有什麼好的辦法,主要是出於升拆商業考慮,防止代碼被盜.
6. 求ASP.NET MVC4的完整案例教程!
需要安裝WindowsPowerShell2.0,從微軟網褲螞站岩棗下載安裝/zh-cn/library/粗純拆ff637750%28v=azure.10%29.aspx