블로그 이미지
Sunny's

calendar

1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30

Notice

2011. 7. 12. 13:07 ASP.NET
Just return a JsonResult.
Here is an example I am using in production:
public partial class StudentController : BaseController {
    public StudentController(RESTContext portalContext)
        : base(portalContext) { }

    [HttpGet, Url("organizations/{organizationId?}/students")]
    public virtual JsonResult List(Guid? organizationId) {
        if (organizationId != RESTContext.OrganizationId)
            throw new HttpNotAuthorizedException();

        var query = RESTContext.GetQuery<IQuery<StudentCasesReport>>()
            .Where(x => x.OrganizationId, organizationId)
            .OrderBy(x => x.LastName, SortOrder.Ascending);
        var cases = query.Execute(IsolationLevel.ReadUncommitted);

        return Json(cases, JsonRequestBehavior.AllowGet);
    }

    [HttpGet, Url("organizations/{organizationId?}/students/{studentId?}")]
    public virtual JsonResult Get(Guid? organizationId, Guid? studentId) {
        if (studentId.IsNull())
            throw new HttpNotFoundExecption();

        if (organizationId != RESTContext.OrganizationId)
            throw new HttpNotModifiedException();

        var query = RESTContext.GetQuery<IQuery<StudentCasesReport>>()
            .Where(x => x.OrganizationId, organizationId)
            .Where(x => x.StudentCaseId, studentId)
            .OrderBy(x => x.LastName, SortOrder.Ascending);
        var cases = query.Execute(IsolationLevel.ReadUncommitted).FirstOrDefault();

        if (cases.IsNull())
            throw new HttpNotFoundExecption();

        return Json(cases, JsonRequestBehavior.AllowGet);
    }
}
posted by Sunny's
2011. 5. 20. 14:55 ASP.NET

MVC 2 서버에 등록후 정상 동작 안할경우 아래 내용 추가해준다..

C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll

 






posted by Sunny's
2010. 11. 24. 09:48 ASP.NET

Migrating a large web application to ASP.NET MVC

Recently I had the luck of migrating some classic ASP pages to ASP.NET MVC. I would share some of the experiences below.

ASP.NET webform and ASP.NET MVC can coexist just fine

We have a huge existing ASP.NET webform application with thousands of pages. The challenge therefore is that any addition developed using ASP.NET should not affect the operation of existing webform pages. The mixing of ASP.NET Webform and MVC has been studied previously by many people. It is fairly easy to find some articles by searching “asp.net mvc and webforms together” on your favorite search engine. Basically, we need to include 3 additional DLLs in the web application:

  • System.Web.Routing
  • System.Web.Abstractions
  • System.Web.Mvc

The System.Web.Routing is not part of ASP.NET MVC, but is used by MVC to route a web request to a controller. The System.Web.Abstractions add a wrapper to some built-in asp.net classes such as Request, Response, Session to decouple MVC code from the ASP.NET built-in classes so that these classes can be mocked in testing projects.

The first step to enable routing is to add the URLRoutingModule to the list of HTTP Modules in web.config:

<add name="UrlRoutingModule" type="System.Web.Routing.UrlRoutingModule,System.Web.Routing, Version=3.5.0.0,Culture=neutral, PublicKeyToken=31BF3856AD364E35" />

The next step is to configure the route. In order not to interfere with the operation of existing asp.net pages, we want to exclude all of them from routing in global.asax:

routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

routes.IgnoreRoute("{resource}.aspx/{*pathInfo}");

routes.IgnoreRoute("{resource}.asmx/{*pathInfo}");

routes.IgnoreRoute("{resource}.svc/{*pathInfo}");

routes.IgnoreRoute("{resource}.ashx/{*pathInfo}");

AreaRegistration.RegisterAllAreas();

In the last line, we used an ASP.NET feature called Areas that I will discuss later.

The third step is to add a bunch of namespaces to <Pages> in web.config so that some MVC namespaces can be used in MVC view pages. We skipped this step because we do not want to affect the existing pages with bunch of new namespaces. We will do this as part of the Area implementation.

ASP.NET MVC allows 100% of the code in the library DLLs

In order to allow developers work independently, we actually split the application into multiple web applications. By default, ASP.NET MVC project put models, views and controllers in a single project. It is in fact very easy to move models and controllers into a separate library DLL, leaving the web application project only the view pages. On deployment, we simply deploy the DLLs to the bin directory of the application root, and the view pages into directories under the Areas folder (see below).

The ASP.NET MVC Areas feature is one of the best feature in MVC 2 for large projects

There are many resources about MVC Areas on the internet. For example, one can read Phil Haack’s original article on the subject. With areas, the responsibility for registering route is delegated to a subclass of AreaRegistration which now lives in our library project. When AreaRegistration.RegisterAllAreas() is called, ASP.NET will search for all AreaRegistration subclasses in all assemblies in the bin dir so that we do not have to modify the global.asax when we add new areas.

In the AreaRegistration subclass, we would do something like:

public override void RegisterArea(AreaRegistrationContext context)

{

context.MapRoute(

"Services",

"Sub1/Sub11/Sub111/{controller}.mvc/{action}/{id}",

new { action = "Index", id = "" },

new string[] { "My.Custom.Namespace.Controllers" }

);

}

Note that we use an optional parameter to route the request to the controllers under particular namespace so that we can retain our existing namespace structure. Also, this approach allows us to blend the new mvc URLs into the existing application URLs very well.

Our web applications are only left with views. We just need to deploy these views to the web server under appropriate area directories. This is how an Areas directory may look like:

image

Note that we have a web.config in the Areas directory? That is the place we add a HttpNotFoundHandler to protect all the views from getting accessed directly. We also add the appropriate attributes, and namespaces to the <Pages> element so that we apply these configurations only to the view pages.

Summary

In summary, ASP.NET MVC allows us to put 100% of code into many library dlls that can be independently developed. The areas feature allows us to delegate the responsibility of route registration to each individual dll as well as centrally apply namespaces and attributes to view pages without affecting the existing asp.net webform pages.

출처 : http://weblogs.asp.net/lichen/archive/2010/11/20/migrating-a-large-web-application-to-asp-net-mvc.aspx

posted by Sunny's
2010. 11. 17. 09:19 ASP.NET
몇일 쉬었더니 엄청나게 많은 콘텐츠가 올라 왔습니다.
News+를 실시간으로 받아보고 싶으신 분들은 Twitter @winkey7을 지금 팔로우 해주세요
오늘은 ASP.NET MVC에 관한 정보가 많이 올라왔습니다. 
다음 호 부터는 좀 더 보시기 좋게 정리해서 올려 드리도록 하겠습니다.
그럼 링크 드립니다. ^^

SharePoint 2010 BrowserCapabilitiesPanel control

Learn 8pen via Silverlight Demo

WP7 Panorama: Smoothly fading the background (and enabling fading when changing, too)

JEANS

ASP.NET Ajax will not be left behind the HTML5 rush

MVC 3 RC Enhancements

Code Gallery Tools App

Microsoft Code Sample for developers

ASP.NET MVC 3: Server-Side Comments with Razor

In Honor of Silverlight NOT Dying….

ASP.NET MVC 3: Server-Side Comments with Razor

Using the Entity Framework to Reduce Network Latency to SQL Azure

Windows Azure Storage Client Library: CloudBlob.DownloadToFile() may not entirely overwrite file contents

Visual Studio improves Help Viewer for Visual Studio 2010 Service Pack 1

A few quick ASP.NET MVC 3 Installation Notes

A few quick ASP.NET MVC 3 Installation Notes

Razor Template in ASP.NET MVC 3

MVC's IgnoreRoute syntax

Thought Leaders in the Cloud: Talking with Jonathan Ellis, Co-Founder of Riptano

New Microsoft Whitepaper Outlines the Economics of Cloud Computing

Real World Windows Azure: Interview with Jeff Yoshimura, Head of Product Marketing, Zuora

2 of 10 - Make sure your buttons are visible, even when the keyboard is displayed.

Take advantage of Windows Summit 2010 to learn about IE9

Elsewhere on the Web

Denali and Juneau

My TechEd Europe 2010 Presentations

Join the TFS development team and help shape the ALM industry

Help improve MSDN – give them your feedback

Join the TFS development team and help shape the ALM industry

TFS2010: Update Activity Logging Cleanup Interval

Asynchrony in C# 5 Part Six: Whither async?

How Do I: Save Images to the Pictures Hub and Retrieve them back from the Hub in a Windows Phone 7 Application?

How do I: Use Push Notifications in a Windows Phone 7 Application?

WCF HTTP URL ACL Utility Scripts

Windows Server AppFabric DB Reset Powershell Script

Retention Policy for document library in SharePoint 2010

SEO Toolkit for SharePoint?

New Whitepaper Details the Windows Azure Programming Model

Breaking Change for Windows Azure Drive Beta in Guest OS 1.8 and 2.0

Breaking Change for Windows Azure Drive Beta in Guest OS 1.8 and 2.0

ASP.NET Web Application: Publish/Package Tokenizing Parameters

Introduction to jQuery for ASP.NET Developers

Announcing the ASP.NET MVC 3 Release Candidate

Windows Azure Diagnostics Viewer

Thought Leaders in the Cloud:  Talking with Charlton Barreto, Technology Strategist at Intel

Web Page Performance in a Standards Compliant and Interoperable way

Simple Semantics With Microformats, Part 4

TFS Integration Platform – New Migration templates for SfTS Team Project Process Template

Windows Azure Diagnostics Monitor


출처 : http://youngwook.com/tag/NEWS+
posted by Sunny's
2010. 11. 12. 09:45 ASP.NET

 This morning the ASP.NET team shipped the ASP.NET MVC 3 RC (release candidate). You can download it here.

ASP.NET MVC 3 is a pretty sweet release, and adds a ton of new functionality and refinements.  It is also backwards compatible with ASP.NET MVC V1 and V2 – which makes it easy to upgrade existing apps (read the release notes for the exact steps to do so).  You can learn more about some of the great capabilities in ASP.NET MVC 3 from previous blog posts I’ve done about it:

Today’s ASP.NET MVC 3 RC build includes several additional feature refinements (in addition to bug fixes, tooling improvements, perf tunings, etc).  This blog post covers the improvements specific to today’s release.  Please review my previous posts to learn more about the many, many other ASP.NET MVC 3 features and improvements introduced in prior previews/betas.

Razor Intellisense within Visual Studio

Colorization and intellisense support for Razor-based view templates is now supported within Visual Studio and the free Visual Web Developer Express. 

Intellisense works for HTML, C#, VB, JavaScript and CSS when editing within razor based view templates:

image

You get full C#/VB code intellisense – including against HTML helper methods (all of the existing Html helper methods in ASP.NET MVC also work just fine in Razor based views):

image

We also provide intellisense for Razor keywords and directives:

image

Note below how after setting the @model directive to be a Product, the strongly-typed HTML helpers (and the “Model” property within the template) are now typed correctly to provide intellisense for a “Product” class:

image

We are still doing final performance tuning on the editor (and have several optimizations that just missed today’s build).  If you encounter a scenario where intellisense either doesn’t seem to work or seems slower than it should be – please send us a repro so that we can verify that our latest builds have it fixed.

NuGet Package Manager

I blogged about a new, free, open source package manager last month - which at the time we were calling “NuPack”.  We’ve since renamed NuPack to NuGet. Today’s ASP.NET MVC 3 release automatically installs it as part of the setup.

You can use NuGet to easily download and install both commercial and open source libraries within your projects.  For example, to install NHibernate and a LINQ extension library that someone has built for it, I could type “install-package NHibernate.Linq” within the NuGet package manager console inside Visual Studio:

image

When I press enter NuGet will automatically download all of the libraries (and their dependencies) and setup my ASP.NET MVC 3 project to use them:

image

There are now hundreds of open source .NET libraries within the NuGet package feed, and the list will continue to grow over time. 

We think NuGet will enable all .NET developers (not just ASP.NET MVC ones) to be able to more easily leverage and share functionality across the community, and make building .NET  applications even better. 

Watch Scott Hanselman’s PDC Talk

Scott Hanselman gave the highest-rated talk at PDC this year, which he called “ASP.NET + Packaging + Open Source = Crazy Delicious”.  It is a “no slides” talk that demonstrates how to code an application from start to finish using ASP.NET MVC 3, Razor, NuGet, EF Code First, SQL CE and a bunch of other cool things.

image

You can watch the talk online or download it (by right-clicking and choosing “save as” from one of the links below):

- Low Bandwidth WMV Video (about 258 megs)

- Low Bandwidth MP4 Video (about 120 megs)

I highly recommend watching it – it is both entertaining, and demonstrates how all the pieces of the ASP.NET MVC 3 stack (and especially NuGet) fit together.

Partial Page Output Caching

ASP.NET MVC has supported output caching of full page responses since V1.  With ASP.NET MVC V3 (starting with today’s RC) we are also enabling support for partial page output caching – which allows you to easily output cache regions or fragments of a response as opposed to the entire thing.  This ends up being super useful in a lot of scenarios.

Output caching just a region of a page is really easy to-do.  Simply encapsulate the region you want to output cache within a child action that you invoke from within the view that you are rendering.  For example, below I have a product listing page, and I want to output a “Daily Specials” section on the page as well:

image

Above I’m using the Html.Action() helper method to call the SalesController.DailySpecials() child action method.  Notice that I’m passing a category parameter to it above – which will allow me to customize the “Daily Specials” I display based on what types of products the user is currently browsing (that way if they are browsing “computer” products I can display a list of computer specials, and if they are browsing “baby” products I can display diaper specials).

Below is a simple implementation of the SalesController.DailySpecials() method.  It retrieves an appropriate list of products and then renders back a response using a Razor partial view template:

image

Notice how the DailySpecials method above has an [OutputCache] attribute on it.  This indicates that the partial content rendered by it should be cached (for 3600 seconds/1 hour).  We are also indicating that the cached content should automatically vary based on the category parameter.

If we have 10 categories of products, our DailySpecials method will end up caching 10 different lists of specials – and the appropriate specials list (computers or diapers) will be output depending upon what product category the user is browsing in.  Importantly: no database access or processing logic will happen if the partial content is served out of the output cache – which will reduce the load on our server and speed up the response time.

This new mechanism provides a pretty clean and easy way to add partial-page output caching to your applications.

Unobtrusive JavaScript and Validation

I discussed several of the validation and JavaScript/AJAX improvements coming in ASP.NET MVC 3 with in my blog post about the first ASP.NET V3 preview release.

One of the nice enhancements with ASP.NET MVC V3 is that the AJAX and Validation helpers in ASP.NET MVC now both use an unobtrusive JavaScript approach by default. Unobtrusive JavaScript avoids injecting inline JavaScript into HTML markup, and instead enables cleaner separation of behavior using the new HTML 5 “data-“ convention (which conveniently works on older browsers – including IE6 - as well). This makes your HTML smaller and cleaner, and makes it easier to optionally swap out or customize JS libraries.  The Validation helpers in ASP.NET MVC 3 also now use the jQueryValidate plugin by default.

Client Side Validation On By Default

With previous versions of ASP.NET MVC (including last month’s ASP.NET MVC V3 beta) you needed to explicitly call Html.EnableClientValidation() within your views in order to enable client-side validation to take place.  Starting with today’s RC that is no longer required, and client-side validation (using an unobtrusive approach) is now enabled by default (you can turn this off if you want through a config setting in web.config).

You do still need to reference the appropriate jQuery+jQuery Validation libraries within your site for the client-side validation to light-up.  Because you explicitly reference the JavaScript files, you can choose to either host them on your own server or reference them from a CDN (content delivery network) like Microsoft’s or Google’s. 

Remote Validator

An additional validation feature that is new with today’s RC is support for a new [Remote] validation attribute that enables you to take advantage of the jQuery Validation plug-in’s remote validator support.  This enables the client-side validation library to automatically call a custom method you define on the server to perform validation logic that can only be done server-side.  It provides a very clean way to integrate scenarios like this within your client-side validation experience.

Granular Request Validation

ASP.NET MVC has built-in request validation support that helps automatically protect against XSS and HTML injection attacks.  Sometimes, though, you want to explicitly turn off request validation for some scenarios where you want users to be able to post HTML content (for example: blog authoring or CMS content editing). 

You can now add a [SkipRequestValidation] attribute to models or viewmodels that disables request validation on a per-property basis during model binding:

image

Adding the above attribute to your model/viewmodel enables you to set it once and have it apply in all scenarios.

Other Improvements in the RC

Below is a partial list of other nice improvements in today’s RC:

Improved “New Project” Dialog Box:

When you create an ASP.NET MVC 3 Project you are presented with a dialog like below:

image

The above dialog is now extensible, and you can add additional starter templates, view engines, and unit test project frameworks to it.  We’ll be releasing additional starter templates over time (that will show up in the list) to make it even easier to get up and running on new projects.

Scaffolding Improvements

A number of small, but nice, improvements have been made to the default ASP.NET MVC scaffold templates.  The templates now do a better job of identifying ID/Primary Key properties on models, and handle them appropriately (for example: they now create appropriate links for edit/delete/etc).  The Create/Edit scaffolds also now use Html.EditorFor() by default instead of Html.TextBoxFor() – which makes it easier for you to customize/tweak how your models are displayed.

Add-View Dialog Box Improvements

When you use the Add->View dialog box to add a view that is strongly-typed, the Add View dialog box now filters out more non-applicable types and is sorted/organized in a way that makes it easier to find what you are looking for.

Session-less Controller Support

You can now indicate whether you want a Controller class to use session-state – and if so whether you want it to be read/write or readonly. 

Razor Model Dynamic By Default

If you do not specify a @model directive within your Razor views, the “Model” property on the page will now default to dynamic instead of object.  This enables you to perform late-binding against the model type.  Previously you had to add a ‘@model dynamic” to the top of the file to do this.

New Overloads for Html.LabelFor() and Html.LabelForModel()

New method overloads have been added for the LabelFor() and LabelForModel() helper methods that enable you to optionally specify or override the label text.

Download

A direct link to an installer for the ASP.NET MVC 3 RC can be found here.  It works with both VS 2010 and the free Visual Web Developer 2010 Express.

Please make sure to uninstall any previous ASP.NET MVC 3 releases you have installed on your system (as well as any previous ASP.NET Web Pages setups that you might have installed).

Summary

Today’s ASP.NET MVC 3 RC build contains a bunch of goodness that makes web development with ASP.NET MVC better than ever.  If you have questions or suggestions about the release, or find issues/bugs with it, please post them to the ASP.NET MVC forum on www.asp.net.  The ASP.NET MVC team monitors this forum closely and will be able to help.

We plan on spending the next few weeks monitoring feedback, tuning performance, and fixing the final set of bugs.  Thanks in advance for any issues you send our way!

Hope this helps,

Scott

출처 : http://weblogs.asp.net/scottgu/archive/2010/11/09/announcing-the-asp-net-mvc-3-release-candidate.aspx

posted by Sunny's
2010. 9. 17. 19:34 ASP.NET
posted by Sunny's
2010. 8. 27. 17:34 ASP.NET



C# Naver API 에서 한글 utf8 파라미터 Encode 하기

 

 public static string EncodeText(string textToEncode)
{

            UTF8Encoding utf8 = new UTF8Encoding();
            Byte[] encodedBytes = utf8.GetBytes(textToEncode);
            string tempStr = "";
            foreach (Byte b in encodedBytes)
            {
                tempStr += "%" + string.Format("{0:X}", b);
            }
            return tempStr;

}

posted by Sunny's
2010. 8. 27. 15:58 ASP.NET

In last article, we explored the ASP.net MVC application structure. Today, we will build a MVC application that will consume an RSS feed. I will modify my previous project for RSS Feed. Follow the these steps.

  1. Select the "Controllers" Folder and then right click and click on Controller as shown below.
  2.  

  3. Press Add, and RssFeedController class will be created as shown below. The SyndicationFeed class from System.ServiceModel.Syndicatation makes it easy to work with RSS Feed. The code below uses an RSS feed from weblogs.asp.net to display asp.net weblogs on a page. 
    		
    	
    		using System.ServiceModel.Syndication;        // add a System.ServiceModel.Web.dll reference 	
    	
    		public class RSSFeedController : Controller	
    	
    		{	
    	
    		        public ActionResult RSSFeed() 	
    	
    		       {	
    	
    		          string strFeed = "http://weblogs.asp.net/aspnet-team/rss.aspx"; 	
    	
    		          using (XmlReader reader = XmlReader.Create(strFeed)) 	
    	
    		         { 	
    	
    		                  SyndicationFeed rssData = SyndicationFeed.Load(reader); 	
    	
    		                 return View(rssData); 	
    	
    		         }	
    	
    		     }	
    	
    		}	
    	

  4. Repeat the above step 2, and Add RSSFeed view in Views\RSSFeed folder. Add the following code in RSSFeed view.


    	
    	<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<SyndicationFeed>" %> 
    	
    	<%@ Import Namespace="System.ServiceModel.Syndication"%>
    	
    	<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
    	
    	RSSFeed
    	
    	</asp:Content> 
    	
    	<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
    	
    	<h2>RSSFeed</h2>
    	
    	<% foreach (var item in ViewData.Model.Items) 
    	
    	{ 
    	
    	string URL = item.Links[0].Uri.OriginalString; 
    	
    	string Title = item.Title.Text; 
    	
    	Response.Write(string.Format("<p><a href=\"{0}\"><b>{1}</b></a>", URL, Title)); 
    	
    	Response.Write("<br/>" + item.Summary.Text + "</p>"); 
    	
    	} %>
    	
    	</asp:Content>
    	

  5. Now you can run the project and it will display rss feed from weblogs.asp.net as shown below.



출처 : http://fairnet.com/Blog/post/Consuming-RSS-Feed-in-MVC-ASPNET.aspx
posted by Sunny's
2010. 7. 22. 19:37 ASP.NET

Get Microsoft Silverlight

Additional Downloads

To download, right click the file type you would like and pick ‘Save Target As’ or ‘Save Link As’


출처 : p://www.msteched.com/2010/NorthAmerica/WEB206

posted by Sunny's
2010. 7. 15. 16:14 ASP.NET

Get Microsoft Silverlight  

함께 시작해요! ASP.Net MVC / 서동진 MVP
컴퓨팅 환경이 발전함에 따라 프로그램 역시, 1-tier, 2-tier, 2.5-tier, 3-tier(N-tier) 등으로 발전해왔습니다. 현재 프레임워크 기반의 웹 응용 프로그램을 개발할 경우 Presentation, Business, Data tier 라고 불리우는 기본적인 3-tier 를 채택하여 개발하는 것이 일반적입니다. UX가 화두로 떠오른 요즘, 보여지는 부분에 대한 데이터 관리가 더욱 중요합니다. 구조적이고 체계적인 Presentation tier 개발을 위한 기술로서의 ASP.Net MVC에 대해 소개하고, 이를 이용한 예제를 살펴봅니다.
posted by Sunny's
prev 1 2 3 next