How do you force Visual Studio to regenerate the .designer files for aspx/ascx files?

If you open the .aspx file and switch between design view and html view and back it will prompt VS to check the controls and add any that are missing to the designer file. In VS2013-15 there is a Convert to Web Application command under the Project menu. Prior to VS2013 this option was available … 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

Cannot read configuration file due to insufficient permissions

There is no problem with your web.config. Your web site runs under a process. In iis you can define the identity of that process. The identity that your web site’s application pool runs as (Network Services, Local System, etc.), should have permission to access and read web.config file. Update: This updated answer is same as … Read more

Unrecognized attribute ‘targetFramework’. Note that attribute names are case-sensitive

This typically happens when you have an attribute of targetFramework=”4.0″ in the web.config but the App Pool is set to run ASP.NET 2.0. The targetFramework attribute is entirely unrecognized by ASP.NET 2.0 – so changing it to 2.0 won’t have the desired effect. Contact Support / Your Administrator and have the AppPool switched to 4.0. … Read more

One DbContext per web request… why?

NOTE: This answer talks about the Entity Framework’s DbContext, but it is applicable to any sort of Unit of Work implementation, such as LINQ to SQL’s DataContext, and NHibernate’s ISession. Let start by echoing Ian: Having a single DbContext for the whole application is a Bad Idea. The only situation where this makes sense is … Read more

Stop Visual Studio from launching a new browser window when starting debug?

Open your startup project’s properties (Project → {ProjectName} Properties… from the main menu or right click your project in the Solution Explorer and choose Properties), then navigate to the Web tab and under Start Action choose Don’t open a page. Wait for a request from an external application. You will still be able to use … Read more

Get MIME type from filename extension

For ASP.NET or other The options were changed a bit in ASP.NET Core, here they are (credits): new FileExtensionContentTypeProvider().TryGetContentType(fileName, out contentType); (vNext only) Never tested, but looks like you can officially expand the mime types list via the exposed Mappings property. Use the MimeTypes NuGet package Copy the MimeMappings file from the reference source of … Read more

Server.MapPath(“.”), Server.MapPath(“~”), Server.MapPath(@”\”), Server.MapPath(“/”). What is the difference?

Server.MapPath specifies the relative or virtual path to map to a physical directory. Server.MapPath(“.”)1 returns the current physical directory of the file (e.g. aspx) being executed Server.MapPath(“..”) returns the parent directory Server.MapPath(“~”) returns the physical path to the root of the application Server.MapPath(“https://stackoverflow.com/”) returns the physical path to the root of the domain name (is … Read more

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