Using Windows Domain accounts AND application-managed accounts

The simplest approach is to have 2 different presentation Projects only for Authentication/Authorization. This has the advantage of leaning on existing framework and standard configuration. From there, you decide to either create an AD user for every internet user, or create a DB/Internet user for every AD user. Creating an Identity user for each AD … Read more

Routing optional parameters in ASP.NET MVC 5

Maybe you should try to have your enums as integers instead? This is how I did it public enum ECacheType { cache=1, none=2 } public enum EFileType { t1=1, t2=2 } public class TestController { [Route(“{type}/{library}/{version}/{file?}/{renew?}”)] public ActionResult Index2(EFileType type, string library, string version, string file = null, ECacheType renew = ECacheType.cache) { return View(“Index”); … Read more

Actionresult vs JSONresult

ActionResult is an abstract class that an action can return. The helper methods in Controller (eg, Json(), Content(), View(), …) return different concrete classes that inherit ActionResult, including JsonResult. You should declare your action methods as returning ActionResult, so that they have the freedom to return any concrete result class.

Could not load file or assembly ‘Microsoft.CodeDom.Providers.DotNetCompilerPlatform

We just had this error in one of our test environments. The problem was in the web.config file. The section had settings to reference the DotNetCompilerPlatform assembly, but had the wrong version number. We updated web.config to the proper version number and it fixed the error. <compilers> <compiler language=”c#;cs;csharp” extension=”.cs” type=”Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=, Culture=neutral, PublicKeyToken=31bf3856ad364e35″ … Read more

How to set values to ViewBag in ActionFilterAttribute ASP MVC 5?

You can do like this public class SomeMsgAttribute : FilterAttribute, IResultFilter { public void OnResultExecuted(ResultExecutedContext filterContext) { } public void OnResultExecuting(ResultExecutingContext filterContext) { filterContext.Controller.ViewBag.Msg= “Hello”; } } Using: [SomeMsg] public ActionResult Index() { return View(); }

ASP.NET MVC 5 error handling

The best way is using Global.Asax, because you can manage all types of errors (Ajax calls/ all of unexpected Errors). with others you can’t do it. Like this: protected void Application_Error() { HttpContext httpContext = HttpContext.Current; if (httpContext != null) { RequestContext requestContext = ((MvcHandler)httpContext.CurrentHandler).RequestContext; /* When the request is ajax the system can automatically … Read more

“Trust relationship between … and the primary domain failed” in MVC5 Authentication

So, based on my EDIT, I’ve modified my _Layout.cshtml so that instead of having @if(User.IsInRole(“Admin”)) {…} I have @if(User.Identity.IsAuthenticated && User.IsInRole(“Admin”)) {…} which seems to solve the problem. I believe the problem was that ASP .NET Identity uses an empty WindowsIdentity when no user is authenticated and when I try to check for the User.IsInRole, … Read more