Using different Web.config in development and production environment

In Visual Studio 2010 and above, you now have the ability to apply a transformation to your web.config depending on the build configuration. When creating a web.config, you can expand the file in the solution explorer, and you will see two files: Web.Debug.Config Web.Release.Config They contain transformation code that can be used to Change the … Read more

IIS AppPoolIdentity and file system write access permissions

The ApplicationPoolIdentity is assigned membership of the Users group as well as the IIS_IUSRS group. On first glance this may look somewhat worrying, however the Users group has somewhat limited NTFS rights. For example, if you try and create a folder in the C:\Windows folder then you’ll find that you can’t. The ApplicationPoolIdentity still needs … Read more

MVC3 and Entity Framework

my answer is pretty simple, do not mess up presentation layer (Whole MVC application) with data access logic and data modeling. Have at minimum 4 projects in your Visual Studio Solution, from bottom to the top: 1 – ProjectName.Interfaces (Class library, entities’s interfaces); 2 – ProjectName.DAL (Class library, the only one allowed to even know … Read more

include antiforgerytoken in ajax post ASP.NET MVC

You have incorrectly specified the contentType to application/json. Here’s an example of how this might work. Controller: public class HomeController : Controller { public ActionResult Index() { return View(); } [HttpPost] [ValidateAntiForgeryToken] public ActionResult Index(string someValue) { return Json(new { someValue = someValue }); } } View: @using (Html.BeginForm(null, null, FormMethod.Post, new { id = … Read more

ASP.NET_SessionId + OWIN Cookies do not send to browser

I have encountered the same problem and traced the cause to OWIN ASP.NET hosting implementation. I would say it’s a bug. Some background My findings are based on these assembly versions: Microsoft.Owin, Version=2.0.2.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35 Microsoft.Owin.Host.SystemWeb, Version=2.0.2.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35 System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a OWIN uses it’s own abstraction to work with response Cookies (Microsoft.Owin.ResponseCookieCollection). This … Read more

How to make custom error pages work in ASP.NET MVC 4

My current setup (on MVC3, but I think it still applies) relies on having an ErrorController, so I use: <system.web> <customErrors mode=”On” defaultRedirect=”~/Error”> <error redirect=”~/Error/NotFound” statusCode=”404″ /> </customErrors> </system.web> And the controller contains the following: public class ErrorController : Controller { public ViewResult Index() { return View(“Error”); } public ViewResult NotFound() { Response.StatusCode = 404; … Read more