Digital Tool Factory blog - Page 13 of 34 - Backend web development in Atlanta GA Digital Tool Factory blog - Page 13 of 34 - Backend web development in Atlanta GA

The Digital Tool Factory Blog

How to fix problems the Mailbox unavailable. The server response was: 5.7.1 Message rejected as spam by Content Filtering error

The Problem:

You are trying to send an email in C# from your website (using Exchange as the email server), but you get the error message

Mailbox unavailable. The server response was: 5.7.1 Message rejected as spam by Content Filtering.

whenever you send the email.  It is clearly not spam.

The Cause:

You are triggering a spam filter based on the number of words and characthers in the sample email you’re sending.

The Solution:

You should increase the number of words in the body of your email by five or more.  It’s strange, but it works.


17
Feb 12


Written By Steve French

 

How to Fix Missing records in Linq to Entities

The Problem

You are attempting to use Linq to Entities in the standard way, your linq model does not seem to have any records attached.  You have missing records in Linq to Entities.

You look in the database, and the proper record is there.  You do a

context.MyEntry.Count().ToString()

and it tells you there is one record there, but still when you attempt to actually retrieve a record, for example like

context.MyEntry.First().FirstName

you get a white screen.  What gives?

The Cause

It turns out the offending code looks like this

namespace MyProject.Models
{
	public class MyEntry
	{
		[Key]
		public int MyEntryId { get; set; }
                public string EmailAddress { get; set; }
                public string LastName { get; set; }
                public string FirstName;
	}
}

The Solution

Did you notice what was missing?  You don’t have the needed

{ get; set; }

after FirstName, so Linq To Entities will not retrieve the record for the database.  It’s always hard to see something missing, it took me about 20 minutes and lots of checking the wrong places to see the omission with this problem.


14
Feb 12


Written By Steve French

 

ASP.Net MVC 3 In Review – One Year Later

'F'kin Computers.' photo (c) 2011, Cameron - license: http://creativecommons.org/licenses/by-sa/2.0/It’s been a little over a year since I’ve devoted myself to Asp.net MVC 3 and on the whole I’m quite impressed.  Microsoft seems to have picked a definite direction for the web (the Microsoft Web Platform Installer makes a nice guide for it), and I like it.  Here is my broad review, please bear in mind I’ve been doing asp.net webforms for about ten years.

The Pros of ASP.Net MVC 3

  1. The Razor View Engine – Brevity is wonderful
  2. The integration with Sql Server and Entity Framework CodeFirst
  3.  The full integration with JQuery
  4. The bare metal approach to html, it is much easier to find bugs in the code when there is less code.
  5. The full integration with Visual Studio 2010 – it is nice to have the platform and the IDE work fully together
  6. NuGet!  The single best way to install add-ons.
  7. The ease of testing your code via the test capabilities of Visual Studio

 

The Cons of ASP.Net MVC 3

  1. It is a pain to test actual data.  With the advent of code-first one would think that you could simply have a test database, but there is no way.  One has to use db fakes, which makes your entire testing a bit less useful.
  2. Coded User Interface Tests are not baked into the system in any way, and for no particular reason one cannot have CUITS in the same solution as the most popular ASP.net  MVC 3 scaffolding packages.

On the whole, I am a huge fan – for more information about it, check out the wonderful work that Shawn Wildermuth and Scott Hanselman have been doing.


14
Feb 12


Written By Steve French

 

How to fix more problems with ASP.net MVC 3 RouteValues

The Problem

You want to create urls that look something like http://SomeSite.com/Categories/Industrial/Fasteners/3.8-MM-Titanium-Wrench-Bolts/ so your site can rank extra high when people search for those profitable 3.8 MM Titanium Wrench Bolts. And in natural, RESTful fashion, your site and database is structured so that the Wrench Bolts are in a subcategory of Fasteners, which are part of the Industrial Category

The Cause:

None really, I’m just listing how one does this sort of thing.

The Solution

Firstly you have to define your route in your global.asax file, in the Register Routes section

routes.MapRoute(
“ItemInd”, // Route name
“Categories/{CategoryName}/{SubCategoryName}/{id}”, // URL with parameters
new { controller = “Product”, action = “Details”, CategoryName = “”, SubCategoryName = “”, id = “” } // Parameter defaults
);

a
Then you have to set your Route Values
Here is an ActionLink helper –

@Html.ActionLink(p.Name, “Details”, new { controller = “Product”, action = “Details”, CategoryName = p.SubCategory.Category.Name, SubCategoryName = p.SubCategory.Name, id = p.Name })

And if you want to use the URL.Action helper, here is what that would look like.

<a href=”@Url.Action(“Details”, “Product”, new { controller = “Product”, action = “Details”, CategoryName = p.SubCategory.Category.Name, SubCategoryName = p.SubCategory.Name, id = p.Name })”>Some Text</a>

as you might suspect, the new { controller = “Product”, action = “Details”, CategoryName = p.SubCategory.Category.Name, SubCategoryName = p.SubCategory.Name, id = p.Name } maps exactly to the corresponding parts in the global.asax file.

This wasn’t really a how to fix problem, but really more about using asp.net mvc 3 RouteValues.  I’ve found a lack of documentation on how to make relatively complicated urls, so I thought this would be a start!


14
Feb 12


Written By Steve French

 

Stronico gets absorbed by Digital Tool Factory

I am giving up the ghost on Stonico.com, and I will soon be shutting down the site and moving 200+ posts from the Stronico blog over here to the Digital Tool Factory blog so they can be part of an actively updated site (thank you 301 redirects).  I expect that to happen slowly over the next two weeks.

Stronico has been a lot of fun and a magnificent learning experience, in product development, programming and business in general.  Primarily what I learned was that there is no market for a visual contact management system. Live and learn!  I with I’d done more research and found it out earlier (like everyone says) but life is one long experiment.


10
Feb 12


Written By Steve French

 

How to fix problems with Linq to Xml Namespaces

The Problem

You are trying to read data out of a standard xml file.  I found a great Linq to Xml tutorial here.  You get code that looks something like this

XDocument data = XDocument.Load(HttpContext.Current.Server.MapPath("~/Invoices.xml"));
List<Invoice> lst = new List<Invoice>();
lst= (from c in data.Descendants("invoice")
select new Invoice
{
ClientName = c.Element("client").Value,
InvoiceDate = Convert.ToDateTime(c.Element("date").Value),
}).ToList();

and you get nothing but object type no found errors.  Why?  You have problems with linq to xml namespaces.

The Cause:

The xml file you are trying to read is using a NameSpace!

The Solution:

Add in the namespace declaration and append it to the file in the right places, your code should look something like the below.

XDocument data = XDocument.Load(HttpContext.Current.Server.MapPath(“~/Invoices.xml”));
XNamespace ns = XNamespace.Get(“http://www.SomeProvider.com/api”);
List lst = new List();
lst= (from c in data.Descendants(ns + “invoice”)
select new Invoice
{
ClientName = c.Element(ns + “client”).Value,
InvoiceDate = Convert.ToDateTime(c.Element(ns + “date”).Value),
}).ToList();

Do you see the “ns + ” part?  That tells C# to keep your data and the xml data apart.  And please note, you have to use it everywhere you reference a part of the xml document (I spent an hour finding that out).

That’s it!  Happy Coding.


05
Feb 12


Written By Steve French

 

Make Sure to Claim Your About.Me Page

A new service has arisen lately that claims to be a yellow pages for people on the internet.  A page that is about, well… me.  Unlike all previous efforts to create such a thing, About.Me might actually work.  You can see my profile here.

It differs from Facebook in that About.Me is a public site, so it would be a good idea to claim your name while you can before it gets highjacked by the evildoers of the internet.  It’s a free service, and it is probably the best thing you can do to protect your “personal brand”, i.e. the thing that people find when they Google you

Claim Your About.Me page now.

Digital Tool Factory is in no way affiliated with About.Me, and we get nothing from advocating their service.  Many clients have asked us about it lately so we thought we would make it part of the newsletter.


01
Feb 12


Written By Steve French

 

How to fix alignment problems in IE 9

The Problem

You have a beautiful, syntactically valid piece of html that SHOULD be aligned center in all browsers, and is aligned center in FireFox and Chrome, but refuses to align center in IE 9.

The Cause

I encountered this when I built the WordPress theme for this very blog.  The cause of alignment problems in IE 9 is that IE 9 wants to render the page in “Quirks” mode, even if the doctype is valid.  I’m sure there is a reason,  but the solution is so simple, who really cares?

The Solution

Just add the following bit of code into the system

<meta http-equiv=”X-UA-Compatible” content=”IE=9″ >

And quirks mode is gone!  The alignment problems in IE 9 are gone! It will now render properly in a modern format.


31
Jan 12


Written By Steve French

 

The how to fix series

I’ve done this elsewhere – but I’m going to start documenting any odd technical problems that take me more than 15 minutes to solve, largely so I have a reference when I have the same problem again.  Everything will be in a  “The Problem, The Cause, The Solution” format. There will be many posts in the how to fix series I assure you.


30
Jan 12


Written By Steve French

 

No one ever told me that making WordPress themes would be this easy

Had I known, I would have started years ago…


17
Jan 12


Written By Steve French

 




Copyright 2011 Digital Tool Factory. All Rights Reserved. Powered by raw technical talent. And in this case, WordPress.