Home / ASP.NET Weblogs

Latest Microsoft Blogs

Browse by Tags

Related Posts

  • Presentation Tips Learned From My (Many) Mistakes

    One aspect of my job that I love is being able to go in front of other developers, my peers, and give presentations on the technologies that my team and I build. I’m very fortunate to be able to do so, especially given the intense stage fright I used to have. But over time, through giving multiple presentations, the stage fright has subsided to mere abject horror levels. Even so, I’m still nowhere near the numbers of much more polished and experienced speakers such as my cohort, Scott Hanselman . Always looking for the silver lining , I’ve found that my lack of raw talent in this area has one great benefit, I make a lot of mistakes. A crap ton of them. But as Byron Pulsifer says, every mistake is a an “opportunity to learn”, which means I’m...


  • Copying Files Over Remote Desktop

    Here’s a handy tip I just recently learned from the new intern on our team ( see, you can learn something from anyone on any given day ). I’ve long known you could access your local drives from a remote machine. For example, start up a remote desktop dialog. Then expand the dialog by clicking on Options , then check the Local Resources tab. Make sure Clipboard is checked, and then hit the More… button. Now you can select a local disk to be shared with the remote machine. For example, in this case I selected my C: drive. As you can see in the screenshot, the file explorer has another drive named “ C on HAACKBOOK ” which can be used to copy files back and forth from my local machine to the remote machine. But here’s the part I didn’t know. Let...


  • ASP.NET MVC Tip #50 – Create View Models

    Recently, I noticed a nice pattern in the Nerd Dinner application. Nerd Dinner uses strongly typed view model classes to pass data from a controller to a view. This pattern provides you with a convenient way of representing complex view data. Note: If you haven’t downloaded the Nerd Dinner sample ASP.NET MVC application yet, you really should. It is a really easy to understand sample application that you can use as a great introduction to ASP.NET MVC. You can download it from the http://www.ASP.net/mvc page. In an ASP.NET MVC application, you pass data from a controller to a view by using view data. There are two ways that you can use view data. First, you can use view data as an untyped dictionary. For example, the controller in Listing 1 returns...


  • ASP.NET MVC Tip #48 – Disable Request Validation

    By default, the ASP.NET MVC framework prevents you from submitting form data that contains potentially malicious content. This feature is called request validation. For example, submitting the following text in an HTML input field causes the ASP.NET MVC framework to throw an exception (Figure 1): <script>Alert(‘I am evil!’);</script> Figure 1 – An evil form post This is a good feature. You don't want people sneaking scripts into your website that can steal passwords or other sensitive user information. Normally, you want to leave request validation enabled. There are situations, however, when it is perfectly legitimate to want people to submit text that contains HTML markup to a website. For example, you might be hosting a discussion...


  • ASP.NET MVC Tip #47 &ndash; Using ResolveUrl in an HTML Helper

    Yesterday, I was creating a simple HTML helper for displaying images. Nothing fancy. The code for the helper is contained in Listing 1. Listing 1 – Helpers\ImageHelper.cs using System.Web.Mvc; using System.Web.Routing; namespace MvcApplication1.Helpers { public static class ImageHelper { public static string Image(this HtmlHelper helper, string id, string url, string alternateText) { return Image(helper, id, url, alternateText, null); } public static string Image(this HtmlHelper helper, string id, string url, string alternateText, object htmlAttributes) { // Create tag builder var builder = new TagBuilder("img"); // Create valid id builder.GenerateId(id); // Add attributes builder.MergeAttribute("src", url); builder.MergeAttribute...


  • ASP.NET MVC Tip #46 &ndash; Don&rsquo;t use Delete Links because they create Security Holes

    I created a sample ASP.NET MVC application that I plan to post at the http://ww.ASP.net/mvc website. While the application was being code reviewed by the ASP.NET MVC Feature team, a surprising objection surfaced. The application is extremely simple. It contains a view that renders a list of database records. Next to each record, there is an Edit link and a Delete link (see Figure 1). Pretty standard stuff. Or, so I thought… Figure 1 – A Grid of database records Here’s the objection. You should not use a link for deleting a record. Using a Delete link opens up a security hole. The Security Objection In theory, someone could send an email to you that contains an image. The image could be embedded in the message with the following tag: <img...


  • Essential Visual Studio Tips &amp; Tricks that Every Developer Should Know

    In this blog entry, I list the essential tips and tricks that every developer who uses Visual Studio 2008 should know. I wanted to keep this list brief. I also wanted to focus on only those tips and tricks that I use on a daily basis. Almost all of these tips and tricks are just as useful regardless of whether you are building an ASP.NET Web Forms or ASP.NET MVC application. Tip #1 – You don’t need to select a line to copy or delete it I always cringe whenever I see someone select an entire line of code in the Visual Studio code editor before copying the line or deleting the line (see Figure 1). You don’t need to do this. Figure 1 If you want to copy a line of code then you can simply press CTRL-c to copy the line and press CTRL-v to paste the...


  • Essential Visual Studio Tips & Tricks that Every Developer Should Know

    In this blog entry, I list the essential tips and tricks that every developer who uses Visual Studio 2008 should know. I wanted to keep this list brief. I also wanted to focus on only those tips and tricks that I use on a daily basis. Almost all of these tips and tricks are just as useful regardless of whether you are building an ASP.NET Web Forms or ASP.NET MVC application. Tip #1 – You don’t need to select a line to copy or delete it I always cringe whenever I see someone select an entire line of code in the Visual Studio code editor before copying the line or deleting the line (see Figure 1). You don’t need to do this. Figure 1 If you want to copy a line of code then you can simply press CTRL-c to copy the line and press...


  • ASP.NET MVC Tip #45 – Use Client View Data

    In this tip, I explore one approach to building Ajax applications with ASP.NET MVC. I show how you can use view data when building Ajax applications with ASP.NET MVC in the same way as you would use view data when building server-side application. I demonstrate how to create a custom HTML Helper that renders client view data. One of the primary benefits of building an ASP.NET MVC application is that it enables you to build web applications that support a sharp separation of concerns. This sharp separation of concerns enables you to build applications that are highly testable and highly adaptable to future change. Communication between the different parts of an ASP.NET MVC application is extremely constrained. An MVC view only talks to an MVC...


  • ASP.NET MVC Tip #44 – Create a Pager HTML Helper

    In this tip, I demonstrate how you can create a custom HTML Helper that you can use to generate a user interface for paging through a set of database records. I build on the work of Troy Goode and Martijn Boland. I also demonstrate how you can build unit tests for HTML Helpers by faking the HtmlHelper class. This week, I discovered that I desperately needed a way of paging through the database records in two of the sample MVC applications that I am building. I needed a clean, flexible, and testable way to generate the user interface for paging through a set of database records. There are several really good solutions to this problem that already exist. I recommend that you take a look at Troy Goode’s discussion of his PagedList class at...


Page 1 of 6 (54 items) 1 2 3 4 5 Next > ... Last »

Archives