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.

Handling Session and Authentication Timeouts in ASP.NET MVC

PayPal with ASP.NET MVC

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"])
         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(
      request.Method = "POST";
      request.ContentLength = data.Length;

      using (StreamWriter writer = new StreamWriter(request.GetRequestStream()))

      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