I was recently working on updated an older asp.net 3.5 website to asp.net 4.0. Unfortunately we can't upgrade to 4.5 due to the risk of breaking other sites on the same server. Our reason for the upgrade was really to take advantage of the routing ability that was built into asp.net 4.0 for webforms.
If you're looking for help on setting up .net routing you can take a look at a simple 'how to' for setting up routing with WebForms here that I wrote a few years back.
The issue I was having was that IIS was returning a 404 page not found error when I tried to go to a url without the .aspx. I had setup my global.asax file with the correct routing information but it was like IIS was ignoring these rules.
I usually setup a new solution so that it contains multiple projects. There's a project for web files, data files, services, utilities and so on. When I downloaded and setup Entity Framework through Nuget I installed it into my Project.Web (where all my views/controllers are) and to my Project.Data (where my data context is located with my repositories) projects.
I installed EF Migrations to my Project.Data project as this is where my data context file lives. Everything compiles and run but sometimes when using Entity Framework Migrations I noticed that I was getting an error:
Could not load assembly 'Project.Data'. (If you are using Code First Migrations inside Visual Studio this can happen if the startUp project for your solution does not reference the project that contains your migrations. You can either change the startUp project for your solution or use the -StartUpProjectName parameter.)
This morning I wasted about 4 hours on a bug that turned out to be a browser issue rather than a code one.
When using Chrome I noticed that my datetime validation in MVC was failing. This validation was working perfectly in Internet Explorer and Firefox. So what was going on?
If you ever see this exception error message it might be worth checking out that you're validating the files you're reading into your system to confirm that they are the correct file type. Wasted too much time on this error just now, oy!
One of the multilingual sites I work on was recently converted to Arabic. The site was already running with French, German, Polish and a whole host of others but Arabic was our first right to left language on this particular site.
Once we got the right to left stuff working for our HTML - mostly by using the 'direction' attribute in CSS - we noticed that our code was failing when displaying dates in the system.
This particular error caused me some headaches so I decided to blog about it in the hope that it'll help some other poor soul! I have a pretty standard MVC 3 project that uses Entity Framework Code First for handling the database side of things. I decided to update my project to ensure it was using the latest version of all of the packages in use on my project (ninject/entity framework/etc). This particular project was using Entity Framework v4.1, which I had previously updated using NuGet without any problems, so I decided to download and install the latest version from NuGet - ver 4.2.
Setting up ASP.NET webforms to use ASP.NET 4.0s new native routing setup was really easy to do on a recent project I completed. There were only one or two gotcha's but once you know about them you won't have any problems setting routing up on your own projects.
It's a new year and thankfully the work inside in Dragnet Systems shows no signs of slowing down. VGWines.com is a brand new online store for an existing wine retailer based in Kerry, Vanilla Grape Wines Ltd.
To read from a Web.Config file using C# is very easy to do. Let's say we have an appSettings tag in our Web.Config that holds the website title. Inside in our web.config you would have something like this:
To get .net to read this value all you need to do is add this to your code behind page on your site. Be sure to add the System.Web.Configuration namespace as this is not added by default.
using System.Web.Configuration; //read in the SiteName tag from web.config string MySiteName = WebConfigurationManager.AppSettings["SiteName"];If you want more details on how to read from web.config please see my earlier post here
You might also want to write to your web.config file to allow the end user to update this data. To do this you must ensure that the Network Service user (or the ASP.NET user on WinServer 03 or earlier) has modify permissions on your website root folder.
Without the correct permission you will get the following error if you try to add the code below:
An error occurred loading a configuration file: Access to the path 'c:\inetpub\wwwroot\yourwebsitefolder\py39wsfg.tmp' is denied.
Assuming you have setup the correct permissions this code below will allow your web app to write to the web.config file.
//update the SiteName tag in web.config with a new value Configuration config = WebConfigurationManager.OpenWebConfiguration("~"); config.AppSettings.Settings["SiteName"].Value = "New Site Name Value"; config.Save(ConfigurationSaveMode.Modified); ConfigurationManager.RefreshSection("appSettings");