The request was aborted: Could not create SSL/TLS secure channel

I finally found the answer (I haven’t noted my source but it was from a search); While the code works in Windows XP, in Windows 7, you must add this at the beginning: // using System.Net; ServicePointManager.Expect100Continue = true; ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12; // Use SecurityProtocolType.Ssl3 if needed for compatibility reasons And now, it works perfectly. … Read more

ASP.NET MVC – Set custom IIdentity or IPrincipal

Here’s how I do it. I decided to use IPrincipal instead of IIdentity because it means I don’t have to implement both IIdentity and IPrincipal. Create the interface interface ICustomPrincipal : IPrincipal { int Id { get; set; } string FirstName { get; set; } string LastName { get; set; } } CustomPrincipal public class … Read more

Can I set an unlimited length for maxJsonLength in web.config?

NOTE: this answer applies only to Web services, if you are returning JSON from a Controller method, make sure you read this SO answer below as well: https://stackoverflow.com/a/7207539/1246870 The MaxJsonLength property cannot be unlimited, is an integer property that defaults to 102400 (100k). You can set the MaxJsonLength property on your web.config: <configuration> <system.web.extensions> <scripting> … Read more

How do you create a dropdownlist from an enum in ASP.NET MVC?

For MVC v5.1 use Html.EnumDropDownListFor @Html.EnumDropDownListFor( x => x.YourEnumField, “Select My Type”, new { @class = “form-control” }) For MVC v5 use EnumHelper @Html.DropDownList(“MyType”, EnumHelper.GetSelectList(typeof(MyType)) , “Select My Type”, new { @class = “form-control” }) For MVC 5 and lower I rolled Rune’s answer into an extension method: namespace MyApp.Common { public static class MyExtensions{ … Read more

How can I retrieve Id of inserted entity using Entity framework? [closed]

It is pretty easy. If you are using DB generated Ids (like IDENTITY in MS SQL) you just need to add entity to ObjectSet and SaveChanges on related ObjectContext. Id will be automatically filled for you: using (var context = new MyContext()) { context.MyEntities.Add(myNewObject); context.SaveChanges(); int id = myNewObject.Id; // Yes it’s here } Entity … Read more

Regex for password must contain at least eight characters, at least one number and both lower and uppercase letters and special characters

Minimum eight characters, at least one letter and one number: “^(?=.*[A-Za-z])(?=.*\d)[A-Za-z\d]{8,}$” Minimum eight characters, at least one letter, one number and one special character: “^(?=.*[A-Za-z])(?=.*\d)(?=.*[@$!%*#?&])[A-Za-z\d@$!%*#?&]{8,}$” Minimum eight characters, at least one uppercase letter, one lowercase letter and one number: “^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)[a-zA-Z\d]{8,}$” Minimum eight characters, at least one uppercase letter, one lowercase letter, one number and one … Read more

In C#, what is the difference between public, private, protected, and having no access modifier?

Access modifiers From docs.microsoft.com: public The type or member can be accessed by any other code in the same assembly or another assembly that references it. private The type or member can only be accessed by code in the same class or struct. protected The type or member can only be accessed by code in … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)