asp.net-mvc-5

Public Conditional Razor Views with minified JS and CSS

烈酒焚心 提交于 2019-12-05 18:44:14
I am using ASP.NET MVC 5 to develop my website. I'm using Grunt to minify my CSS and JS. Everything works fine, but I need to change the route source of my files if I'm making a publish (release mode) or I'm debugging (I need to read my CSS and JS clearly). Something like this: [Debug Mode] <script src="scripts/myscript.js"></script> [Relase Mode or Public Mode] <script src="dist/myscript.min.js"></script> I have read this post on StackOverflow( Razor view engine, how to enter preprocessor(#if debug) ) and I don't like the proposed solution because I think (not sure) that the loaded Razon View

Secure way to Delete a record in ASP.Net MVC

那年仲夏 提交于 2019-12-05 18:26:20
I want to delete a product from my ASP.Net MVC 5 website. I want to know if adding [AntiForgeryToken] and [Authorize] is enough to secure the Delete operation? View <p>Delete: @Model.Name</p> @using (Html.BeginForm("Delete", "ProductController", FormMethod.Post, new { ProductId = Model.ProductId })) { @Html.AntiForgeryToken() <button type="submit">Delete</button> } Controller [HttpPost] [Authorize] [ValidateAntiForgeryToken] public ActionResult Delete(long ProductId) { /* Do I need to check if the logged in User has permission to delete the product? var product = ProductRepository.Get(Id); if

How to create array of key/value pair in c#?

会有一股神秘感。 提交于 2019-12-05 17:20:35
I have an application that is written on top of ASP.NET MVC. In one of my controllers, I need to create an object in C# so when it is converted to JSON using JsonConvert.SerializeObject() the results looks like this [ {'one': 'Un'}, {'two': 'Deux'}, {'three': 'Trois'} ] I tried to use Dictionary<string, string> like this var opts = new Dictionary<string, string>(); opts.Add("one", "Un"); opts.Add("two", "Deux"); opts.Add("three", "Trois"); var json = JsonConvert.SerializeObject(opts); However, the above creates the following json { 'one': 'Un', 'two': 'Deux', 'three': 'Trois' } How can I

Using of HandleErrorAttribute in ASP.NET MVC application

£可爱£侵袭症+ 提交于 2019-12-05 17:12:36
问题 I have a question about the best way of using HandleErrorAttribute in my MVC 5 application. As we know, we can add this attribute to global filters like that: filters.Add(new HandleErrorAttribute{View = "Error"}); This involves the app to show the 'Error' view every time when an unhandled exception is thrown in any level of app. But, if I have some logic in another global authorize or action filter, that produces some exception, then when the exception is thrown for first time, the app tries

GlobalConfiguration does not contain a definition for Configure

柔情痞子 提交于 2019-12-05 16:57:40
问题 I'm attempting to create an ASP.NET MVC site that uses Database First Entity Framework. I'm using creating a new MVC 5 site in Visual Studio Professional 2013 Update 3 , then adding an ADO.NET Entity Data Model from which I choose EF Designer from database . After that, I create a connection string, select the tables to generate the framework, and all is well. However when I compile it, I receive this error 'MyModel.GlobalConfiguration' does not contain a definition for 'Configure' This is in

Should I use Data Cache or Output Cache for a complex navigation menu?

白昼怎懂夜的黑 提交于 2019-12-05 16:22:32
问题 I am attempting to cache sections of a navigation menu according to different criteria. For example, news and articles need to be refreshed on a duration basis, whereas login and profile stuff should be cached on a per user basis. I'm considering 2 options - would anyone be kind enough to enlighten me about the pros / cons of each? And if possible suggest a better approach to take! Option 1. Simply cache all required html as strings in the Data Cache. Check for user differences manually when

Dead simple ASP.NET MVC 5 password protection?

守給你的承諾、 提交于 2019-12-05 16:20:22
I have an ASP.NET MVC 5 web application running on Azure as a webrole. Is there any way to easily password protect the entire website? I do not want any signup or account handling, just a single password to enter the site (and perhaps a username, but that's not required). Something similar to a .htaccess file. Every example on authentication for ASP.NET MVC I'm looking at comes with an enormous amount of code to implement, and Azure does not seem to be able to support Basic Authentication (at least not easily). ranquild You are right, there is no support for Basic Authentication in ASP.NET MVC

does “BundleTable.EnableOptimizations = true;” automatically minify the files or it will just select the .min if it is available

梦想的初衷 提交于 2019-12-05 15:10:28
问题 I need to know if specifying "BundleTable.EnableOptimizations = true;" will automatically minify the files (js & Css)or it will just select the .min if it is available ? 回答1: One has nothing to do with the other. BundleTable.EnableOptimizations exists merely to provide a way to force bundling in development, where it's disabled by default. In production, it's enabled by default, and unnecessary to specify anything for EnableOptimizations . Either way, though, it only determines whether

validating date format not working

点点圈 提交于 2019-12-05 13:48:00
I'm having problem with date validation. In my View, I have a jQuery datepicker - I changed the format from yy/mm/dd to mm/dd/yy and now I get client-side validation errors. For example, The value '02/25/2014' is not valid for Date of Birth. The Javascript: $('#DateOfBirth').datepicker({ changeMonth: true, changeYear: true, dateFormat: "mm/dd/yy", yearRange: "-90:-5" }); The View Model: [Required] [Display(Name = "Date of Birth")] public DateTime? DateOfBirth { get; set; } The View: @Html.TextBoxFor(m=> m.DateOfBirth, "{0:MM/dd/yyyy}", new { @class = "datepicker" }) Any ideas on this? Thanks.

Why Scripts.Render invoke JsMinify.Process?

青春壹個敷衍的年華 提交于 2019-12-05 13:00:42
I profiled my ASP.NET MVC application and I saw strange a function calls. You can see it on image Always when mvc render layout we invoke system.web.optimization.scripts.render which invoke JsMinify.Process and Minifier.MinifyJavaScript , but I thought what minification should be one time on the start app. Am I right? Maybe must I set some settings for optimization it? Conditions: localhost release BundleTable.EnableOptimizations = true; Great Question! Intuitively, you are right, minification of assets should be performed on application Startup . You assume that assets are delivered