Wednesday, February 29, 2012

How to solve 403 error while deploy ASP.NET MVC?

run "aspnet_regiis –iru"



If you install VS2010 and/or .NET 4 first, then later install IIS, you need make sure IIS is configured to know about ASP.NET 4 otherwise IIS will have no idea how to run ASP.NET 4 applications.
There's a simple workaround:

·        If you are already in this state, drop to the command line and navigate to the FX install directory.  Then run "aspnet_regiis –iru". 

·        Note if you are on a 64-bit machine, run this command from the 64-bit FX install directory – not the 32-bit installation directory.
Reference:
http://www.hanselman.com/blog/ASPNET4BreakingChangesAndStuffToBeAwareOf.aspx


Handling Session and Authentication Timeouts in ASP.NET MVC

http://markfreedman.com/index.php/2012/02/28/handling-session-and-authentication-timeouts-in-asp-net-mvc/

PayPal with ASP.NET MVC

http://www.superstarcoders.com/blogs/posts/paypal-with-asp-net-mvc.aspx

public class CartController : Controller
{
   public ActionResult Index()
   {
      return View();
   }

   public ActionResult Pay()
   {
      PayPalRedirect redirect = PayPal.ExpressCheckout(new PayPalOrder { Amount = 50 });

      Session["token"] = redirect.Token;

      return new RedirectResult(redirect.Url);
   }
}
Here is the PayPal API code that you can include in your solution or a separate library:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Collections.Specialized;
using System.Net;
using System.IO;
using System.Globalization;

public class PayPal
{
   public static PayPalRedirect ExpressCheckout(PayPalOrder order)
   {
      NameValueCollection values = new NameValueCollection();

      values["METHOD"] = "SetExpressCheckout";
      values["RETURNURL"] = PayPalSettings.ReturnUrl;
      values["CANCELURL"] = PayPalSettings.CancelUrl;
      values["AMT"] = "";
      values["PAYMENTACTION"] = "Sale";
      values["CURRENCYCODE"] = "GBP";
      values["BUTTONSOURCE"] = "PP-ECWizard";
      values["USER"] = PayPalSettings.Username;
      values["PWD"] = PayPalSettings.Password;
      values["SIGNATURE"] = PayPalSettings.Signature;
      values["SUBJECT"] = "";
      values["VERSION"] = "2.3";
      values["AMT"] = order.Amount.ToString(CultureInfo.InvariantCulture);

      values = Submit(values);

      string ack = values["ACK"].ToLower();

      if (ack == "success" || ack == "successwithwarning")
      {
         return new PayPalRedirect
         {
            Token = values["TOKEN"],
            Url = String.Format("https://{0}/cgi-bin/webscr?cmd=_express-checkout&token={1}",
               PayPalSettings.CgiDomain, values["TOKEN"])
         };
      }
      else
      {
         throw new Exception(values["L_LONGMESSAGE0"]);
      }
   }

   private static NameValueCollection Submit(NameValueCollection values)
   {
      string data = String.Join("&", values.Cast<string>()
        .Select(key => String.Format("{0}={1}", key, HttpUtility.UrlEncode(values[key]))));

      HttpWebRequest request = (HttpWebRequest)WebRequest.Create(
         String.Format("https://{0}/nvp",PayPalSettings.ApiDomain));
      
      request.Method = "POST";
      request.ContentLength = data.Length;

      using (StreamWriter writer = new StreamWriter(request.GetRequestStream()))
      {
         writer.Write(data);
      }

      using (StreamReader reader = new StreamReader(request.GetResponse().GetResponseStream()))
      {
         return HttpUtility.ParseQueryString(reader.ReadToEnd());
      }
   }
}

Juice UI: Open source ASP.NET Web Forms components for jQuery UI widgets

 Juice UI is a collection of Web Forms components which make it incredibly easy to leverage jQuery UI widgets in ASP.NET Web Forms applications. 

2012-02-28 09h17_29


http://weblogs.asp.net/jgalloway/archive/2012/02/28/juice-ui-open-source-asp-net-web-forms-components-for-jquery-ui-widgets.aspx

Monday, February 27, 2012

How to name a form in ASP.NET MVC razor view?

@using (Html.BeginForm("ActionName", "ControllerName", FormMethod.Post, new { id = "formName" }))
{

}

Data migration feature in Entity Framework 4.3

http://www.bluelemoncode.com/post/2012/02/17/Cool-new-database-migration-feature-of-EF-43.aspx



The database migration feature now allows developers to change the database schema in code first approach

Wednesday, February 22, 2012

How to Prevent SQL Injection in ASP.NET

http://web.securityinnovation.com/appsec-weekly/blog/bid/79150/How-to-Prevent-SQL-Injection-in-ASP-NET


Step 1. Constrain Input
You should validate all input to your ASP.NET applications for type, length, format, and range. By constraining the input used in your data access queries, you can protect your application from SQL injection.

Step 2. Use Parameters with Stored Procedures
Using stored procedures does not necessarily prevent SQL injection. The important thing to do is use parameters with stored procedures. If you do not use parameters, your stored procedures can be susceptible to SQL injection if they use unfiltered input as described in the "Overview" section of this document.

Step 3. Use Parameters with Dynamic SQL

ASP.NET Caching, Micro-Caching, and Performance

http://www.eggheadcafe.com/tutorials/asp-net/2518777b-c584-4305-941a-1a2d1a4b857d/aspnet-caching-microcaching-and-performance.aspx

Caching is your friend. If you have to present data that comes out of a database, and you run a website that gets a lot of traffic and requests, especially if the data is "read only"  (which it almost always is), you can get - in most cases - vastly improved throughput by caching this data for as little as 1/2 of one second. 

Friday, February 17, 2012

ASP.NET MVC 4 Beta Released!

http://weblogs.asp.net/jgalloway/archive/2012/02/16/asp-net-4-beta-released.aspx

ASP.NET Web API

The big new feature since the Developer Preview is the introduction of ASP.NET Web API.
ASP.NET Web API is built for all the other, non-human interactions your site or service needs to support

How to Retrieve Resource Values Programmatically in ASP.NET


        Button1.Text = GetLocalResourceObject("Button1.Text").ToString();
        Image1.ImageUrl =     (String)GetGlobalResourceObject(
            "WebResourcesGlobal", "LogoUrl");
Reference: http://msdn.microsoft.com/en-US/library/ms227982(v=vs.80).aspx

Thursday, February 16, 2012

Parallel processing of concurrent Ajax requests in Asp.Net MVC

http://www.stefanprodan.eu/2012/02/parallel-processing-of-concurrent-ajax-requests-in-asp-net-mvc/


If you want to enable a certain controller to process requests in parallel from a single user, you can use an attribute named SessionState that was introduced in MVC since version 3. It’s not necessary to use a session-less controller in order to achieve parallelism, the Ready-only option of theSessionStateBehavior will let you pass security checks you may have implemented based on Session data.
ParallelController.cs
    [SessionState(System.Web.SessionState.SessionStateBehavior.ReadOnly)]
    [OutputCache(NoStore = true, Duration = 0, VaryByParam = "*")]
    public class ParallelController : Controller
    {
        public JsonResult Get1()
        {
            //read from session
            var x = Session["call"];
            Thread.Sleep(5000);
            return Json(new { obj = "p1" }, JsonRequestBehavior.AllowGet);
        }
        public JsonResult Get2()…
        public JsonResult Get3()…
    

Wednesday, February 15, 2012

SignalR - notifying clients about server events

Use signalR in scenarios where you are polling server after fix interval to check if server has something which client needs to update. With SignalR it becomes very easy to implement solutions which require real time asynch connection with server.
If you are completely new to the term SignalR, then please read this Scott Hanselman's this post and visit SignalR's page on GitHub.

Wednesday, February 8, 2012

Friday, February 3, 2012

More Flexible Routing For ASP.NET Web Pages

RouteTable.Routes.MapWebPageRoute("List/", "~/ListProducts.cshtml");
RouteTable.Routes.MapWebPageRoute("List/{category}/", "~/ListProducts.cshtml");
RouteTable.Routes.MapWebPageRoute("List/{category}", "~/ListProducts.cshtml", new { category = "Beverages" });
RouteTable.Routes.MapWebPageRoute("{product}/{action}", "~/Catchall.cshtml", new { product = "Beer", action = "Drink" }); 
RouteTable.Routes.MapWebPageRoute("{product}/{*action}", "~/Catchall.cshtml", new { product = "Beer", action = "Drink" }); 
RouteTable.Routes.MapWebPageRoute("List/{category}", "~/ListProducts.cshtml", constraints: new { category = "[a-zA-Z]" });

http://www.mikesdotnetting.com/Article/187/More-Flexible-Routing-For-ASP.NET-Web-Pages

Wednesday, February 1, 2012

Google Productivity Secret, Snippets

http://blog.idonethis.com/post/16736314554/silicon-valleys-productivity-secret
During Google’s growth stage, Larry Schwimmer, an early software engineer, stumbled upon a solution deceptively simple, but one that persists to this day at Google and has spread throughout the Valley.  In his system called Snippets, employees receive a weekly email asking them to write down what they did last week and what they plan to do in the upcoming week.  Replies get compiled in a public space and distributed automatically the following day by email.

Cut the Rope, made by HTML5

www.cuttherope.ie
Cut the Rope

Micro Caching in ASP.NET

http://www.superstarcoders.com/blogs/posts/micro-caching-in-asp-net.aspx

Micro Caching

Micro caching is a strategy used to cache data for relatively short amounts of time (in human terms). Most businesses can tolerate a large subset of data being cached for a few minutes and when there are many hundred requests happening per second, a few minutes is an eternity!

Micro Caching and Fetch Locking

Enter a micro cache solution with fetch locking. I wanted to design something really light weight which meant that any locked sections of code ran very efficiently to minimise the lock time. So my micro cache ensures that reads are efficient (as locks are only during writes) and writes are done as quickly as possible.