C#

  • IIS 7 returning 404 error with extension less URL

    iis7 404 error with extensionless url asp.net 4.0

    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.

    C#, IIS7
  • Entity Framework 'could not load assembly' error message

    Cure for Entity Framework Migrations could not load assembly error message

    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.)

  • System OutOfMemoryException Error using System.IO

    system.io error message

    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!

    .Net, C#
  • Arabic culture that uses the Gregorian calendar

    Arabic culture that uses the Gregorian calendar

    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.

  • Entity Framework v4.2 upgrade not working

    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.

  • How to fix WebResource.axd JavaScript errors appearing when using asp.net routing

    I had an issue with one of our asp.net 4.0 websites recently. The site was using web forms, routing and had .net validation controls in use. Everything worked great until I used the validation controls and discovered that I was getting 2 JavaScript errors on every page that used these controls.

  • How to read from and write to the web.config file using C#

    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");
    

  • ← Older Posts

Updates

Follow me online at TwitterFacebook or Flickr. If you want to get in touch with me try emailing me.

Latest Tweets