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

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=1.0.5.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35″ …

Read more

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

Login page on different domain

public class Startup { public void Configuration(IAppBuilder app) { app.UseCookieAuthentication(new CookieAuthenticationOptions { AuthenticationMode = AuthenticationMode.Active, LoginPath = new PathString(“/account/login”), LogoutPath = new PathString(“/account/logout”), Provider = new CookieAuthenticationProvider { OnApplyRedirect = ApplyRedirect }, }); } private static void ApplyRedirect(CookieApplyRedirectContext context) { Uri absoluteUri; if (Uri.TryCreate(context.RedirectUri, UriKind.Absolute, out absoluteUri)) { var path = PathString.FromUriComponent(absoluteUri); if (path == …

Read more

ASP.NET MVC5/IIS Express unable to debug – Code Not Running

For me the solution was a much simpler one. In my Solution Explorer in Visual Studio, I right click on the web project, chose properties and then navigated to the “web” tab. From there I changed the Project URL to another port number. For example, if it was http://localhost:1052 – I changed it to http://localhost:4356. …

Read more