asp.net-mvc-4

Including user model in every view

徘徊边缘 提交于 2021-01-27 11:46:01
问题 I'm creating an ASP.NET MVC4 web site with Forms authentication and am encountering difficulties in the correct way to include multiple models within a view. Specifically, there is a model that belongs to a given view, say "CartModel". However, given the current UI of the site, there is a model used within a partial view that is included in the master layout view with information about the currently logged in user. My current approach for solving this issue is to include the LoginModel as a

asp.net mvc 4, thread changed by model binding?

北慕城南 提交于 2021-01-27 07:13:41
问题 I am using a custom ModelBinder in an MVC 4 application, but it is invoked on a different thread than the request event handlers in global.asax, and this makes setting up a performance profiling context in a ThreadLocal fail. The threadId is in brackets at the start of each line, and you can see that the thread changes when the model binding is invoked, and that is the thread in which the controller action (Index) is executed. [33] | ERROR | MyApp.MvcApplication | Application_BeginRequest [33

asp.net mvc 4, thread changed by model binding?

天大地大妈咪最大 提交于 2021-01-27 07:13:02
问题 I am using a custom ModelBinder in an MVC 4 application, but it is invoked on a different thread than the request event handlers in global.asax, and this makes setting up a performance profiling context in a ThreadLocal fail. The threadId is in brackets at the start of each line, and you can see that the thread changes when the model binding is invoked, and that is the thread in which the controller action (Index) is executed. [33] | ERROR | MyApp.MvcApplication | Application_BeginRequest [33

OutputCache with VaryByCustom not working

跟風遠走 提交于 2021-01-27 06:09:29
问题 I'm trying to implement caching in ASP.NET MVC 4 using the OutputCache attribute. Here is my controller action: [HttpGet] [OutputCache(Duration = CACHE_DURATION, VaryByCustom = "$LanguageCode;myParam", Location = OutputCacheLocation.Server)] public JsonResult MyAction(string myParam) { // this is called also if should be cached! } And here is the GetVaryByCustomString in the Global.asax: public override string GetVaryByCustomString(HttpContext context, string arg) { var pars = arg.Split(';');

OutputCache with VaryByCustom not working

微笑、不失礼 提交于 2021-01-27 06:04:52
问题 I'm trying to implement caching in ASP.NET MVC 4 using the OutputCache attribute. Here is my controller action: [HttpGet] [OutputCache(Duration = CACHE_DURATION, VaryByCustom = "$LanguageCode;myParam", Location = OutputCacheLocation.Server)] public JsonResult MyAction(string myParam) { // this is called also if should be cached! } And here is the GetVaryByCustomString in the Global.asax: public override string GetVaryByCustomString(HttpContext context, string arg) { var pars = arg.Split(';');

Usage of Update-Database in EF Migrations when deployed in Azure

大兔子大兔子 提交于 2021-01-27 05:42:34
问题 Context: I have my ASP.NET MVC4 solution deployed in Azure. My MSSQL Server Database is also there, in Azure. I currently deploy this way: In web.config I change the connection string from local database (sdf) to azure database ( connectionString="Server=tcp:.....database.windows.net, ..." ) Right click on project name (visual studio), and then "Publish" So, my question is : How do I use the Update-database command in the Package Manager Console? Is it this way? Same step #1 from above Run

How do I make Razor read UTF-8 files without BOM?

梦想的初衷 提交于 2021-01-27 01:12:00
问题 We have separated teams for front end and back end work. The front end is using a large diversity of editors to edit the CSHTML and most of them save UTF-8 without a byte order mark. The problem is, Razor expects a BOM to be present. If it's not present it will read the file using the current code page and we get encoding problems. How would I make Razor to accept the UTF-8 files without a BOM ? Apparently the only solution would be to implement an own VirtualPathProvider and thus also a

How do I make Razor read UTF-8 files without BOM?

若如初见. 提交于 2021-01-27 01:08:21
问题 We have separated teams for front end and back end work. The front end is using a large diversity of editors to edit the CSHTML and most of them save UTF-8 without a byte order mark. The problem is, Razor expects a BOM to be present. If it's not present it will read the file using the current code page and we get encoding problems. How would I make Razor to accept the UTF-8 files without a BOM ? Apparently the only solution would be to implement an own VirtualPathProvider and thus also a

Is it possible to read the excel cell value with formula?

给你一囗甜甜゛ 提交于 2021-01-03 05:50:37
问题 In my following code, the value of c4 is coming out zero. C4 cell has formula SUM(C2:C3). Is EPPlus capable of reading cell with formula? Why is c4 being set to zero instead of 12. using (var package = new ExcelPackage(existingFile)) { ExcelWorkbook workBook = package.Workbook; var currentWorksheet = workBook.Worksheets.First(); currentWorksheet.Cells["C2"].Value = 5; currentWorksheet.Cells["C3"].Value = 7; var c4 = Convert.ToDouble(currentWorksheet.Cells["C4"].Value); //c4 is zero. why? }

Can not find system.web.http

戏子无情 提交于 2020-12-30 04:52:00
问题 I have to add a system.web.http assembly reference because I added the HttpConfiguration class to my unit test class library project. When I browse the Add reference dialog I can not find the system.web.http assembly. The class library project has the .Net 4.5.1 framework targeted. 回答1: in order to get the system.web.http you will need to install a nuget package in the nuget command line: Install-Package Microsoft.AspNet.WebApi.Core https://www.nuget.org/packages/Microsoft.AspNet.WebApi.Core/