asp.net-mvc-5

How do I enable ssl for all controllers in mvc application

自闭症网瘾萝莉.ら 提交于 2019-12-04 17:33:22
问题 I have a MVC 5 app and I installed the ssl certificate and I'm now connecting with https, but in my code I had to set the '[requirehttps]' attribute on the homecontroller like so: [RequireHttps] public class HomeController : Controller {} Isn't there a way to set it for the whole application so I don't have to do this for each and every controller I have in the app? 回答1: Use the RegisterGlobalFilters method in your FiltersConfig . public class FilterConfig { public static void

AllowHtml attribute doesn't work

删除回忆录丶 提交于 2019-12-04 17:25:14
I'm trying to implement Tiny MCE text editor to my Create page. I've used [AllowHtml] attribute to my Body property but it still doesn't work. My detail view for the blog still showing html tags. This is my blog entity class. public class Blog { public int Id { get; set; } [Required] public string Title { get; set; } [AllowHtml] [Required] [DisplayName("Content")] public string Body { get; set; } [DisplayName("Created on")] [DataType(DataType.Date)] [Required] public DateTime Created { get; set; } } The pic below shows my create blog page (which shows that I have TinyMCE implemented property

What is the recommended approach for deploying to multiple Azure environments (dev, test, production)?

筅森魡賤 提交于 2019-12-04 17:18:33
I have an C# web application using mvc5. It currently runs on Azure and I have a dev, test, and production instances. What do I need to do to ensure that the database connection strings will automatically change as the application is pushed to each environment? I know this is possible with web.config as you can define Web.Debug.Config, etc, but how would I go about this for different worker roles on Azure? I have been all over the internet looking for a solution. In a nutshell, I would like to do the same approach used for the multiple web.config files but for Azure. As some additional

asp.net MVC5 - Dependency Injection and AuthorizeAttribute

一个人想着一个人 提交于 2019-12-04 17:02:42
问题 I searched a long time for a solution for my problem. I have a custom AuthorizeAttribute that needs a Dependency to a "Service" that has access to a DbContext. Sadly the Dependency Injection did not work in the custom AuthorizeAttribute and was always null. I came up with an (for me) acceptable solution. Now I want to know if my solution can cause unforeseen behaviour? Global.asax.cs CustomAuthorizeAttribute.AuthorizeServiceFactory = () => unityContainer.Resolve<AuthorizeService>();

How to access HTTP StatusDescription in custom error page

不羁岁月 提交于 2019-12-04 16:17:28
When an action (asp.net mvc 5) cannot find something in the database, the user must see a page with a short custom error message e.g. "Invoice 5 does not exist" . Also, the response must have a 404 HTTP code. Another example: when the action is improperly called, the user must see e.g. "Parameter 'invoiceId' is required" . Also, the response must have a 400 HTTP code. I tried to store the custom messages in the HTTP status description and to display them in custom error pages. There are two approaches (afaik): A mvc action: return HttpNotFound("Invoice 5 does not exist"); OR return new

How to install ASP.NET MVC 5 on a server?

蹲街弑〆低调 提交于 2019-12-04 16:16:20
问题 I just updated my website from MVC 4 to MVC 5. Now when I want to run it on my web server instead of my development machine it does not work. It think it is because I need to install the MVC 5 libraries on the server but I can't find them. I downloaded WebMatrix 3 hoping it would provide a way to install it but it only gives me the ability to install MVC 4. What should I install to be able to run a ASP.NET MVC 5 application? (without installing Visual Studio 2013) EDIT: I disabled custom

Is “jquery.unobtrusive-ajax.js” obsolete?

泄露秘密 提交于 2019-12-04 16:14:43
问题 I have an ancient MVC2 solution that I migrated to MVC5 (Visual Studio 2013). I'd like to update the old libraries used in the project with the new ones. I have by eg. the jquery.unobtrusive-ajax.js library. Is it obsolete as by now? I ask because that library references /// <reference path="jquery-1.4.4.js" /> but I upgraded the jQuery (I use the jQuery v1.8.3 by now). If it with what to replace (like jquery.validate.unobtrusive.js (?)) PS. In a default MVC project Visual Studio 2013

Identity (on database creation) error specified key was too long

╄→гoц情女王★ 提交于 2019-12-04 15:41:20
I have here an issue with AspNet Identity and MySql, the issue is error which is really blocking me, this error is following: specified key was too long max key length is 767 bytes Now I followed this tutorial of using MySql with Identity: http://www.asp.net/mvc/tutorials/security/aspnet-identity-using-mysql-storage-with-an-entityframework-mysql-provider I want to say I had progression, because now atleast i get some tables generated in MySQL, but I'm stack on this issue, for a long time i'm trying to solve this, but without success. The error i get is in this part: public void

Visual Studio 2015. Failed to register URL for site access is denied IIS Express. Access denied 0x80070005

我只是一个虾纸丫 提交于 2019-12-04 15:23:39
I enabled SSL in Visual Studio 2015 in order to implement Facebook and Google login locally. I changed the project URL in the Web tab of the project's properties to https://localhost:44300/ and decorated the controller with the RequireHttps attribute - ref @msdn . Everything worked fine locally. I reverted settings to HTTP to test something else and that caused me a problem when I tried to get back to HTTPS. I found this SO question and tried almost every suggested solution. Error detail: Failed to register URL " url " for site " site " application " path ". Error description: Access is denied

How can I use placeholder attribute with Html.EditorFor?

对着背影说爱祢 提交于 2019-12-04 15:02:21
问题 I want to use the placeholder attribute in the Html.EditorFor so I did just like in the first answer: Html5 Placeholders with .NET MVC 3 Razor EditorFor extension? But in the final part, I don't have the EditorTemplates folder so I created it and when I tried to create the string.cshtml view I couldn't because the name "string" is reserved so I chose stringg.cshtml instead and it didn't work! Do I have to change the name elsewhere in my program? I did exactly like the answer... Thank you! 回答1