Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 4 > ASP.NET 4 General Discussion
|
ASP.NET 4 General Discussion For ASP.NET 4 discussions not relating to a specific Wrox book
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 4 General Discussion section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old July 30th, 2012, 06:32 PM
Authorized User
 
Join Date: Jul 2012
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
Default Trying a fetch values from encrypted URL

Hi,
I am sorry if this question is posted somewhere else also, I didn't find it.

I am trying to pass some values in URL(encrypted) from one website to another.
(kind of a custom SSO, but not complete). When I encrypt my URL and controls is shifted from site1 to site2. It gives a "OBJECT MOVED TO HERE" where here is a hyperlink.

Site1 (http://localhost/Login_Website) code
Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;
using System.Security.Cryptography;
using System.Text;
using System.Web.Security;
using System.Data;
using System.Data.SqlClient;

namespace loginControl_test
{
    public partial class _Default : System.Web.UI.Page
    {
        String targetSiteSsoUrl = "http://localhost/Login_Website2/Default.aspx";
        String SECRET_KEY = "HappyCoding";

        protected void Page_Load(object sender, EventArgs e)
        {
            string destinationUrl = Request.QueryString["destinationUrl"];
            string UserName = User.Identity.Name;
            string destination = targetSiteSsoUrl + "?uname=" + HttpUtility.HtmlEncode(UserName) + "&destinationUrl=" + HttpUtility.HtmlEncode(destinationUrl);
            string message = UserName + "|" + destinationUrl;
            string hash = getHash(message);
            destination += "&hash=" + hash;
            Response.Redirect(destination);
        }

        protected string getHash(string message)
        {
            HMACSHA1 sha1 = new HMACSHA1(Encoding.Default.GetBytes(SECRET_KEY));
        	string hash = BitConverter.ToString(sha1.ComputeHash(Encoding.Default.GetBytes(message))).Replace("-", "");
	        return hash;
        }
    }
}

Site2 ((http://localhost/Login_Website2) code

Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Security.Cryptography;
using System.Text;
using System.Web.Security;

namespace loginControl_test2
{
    public partial class _Default : System.Web.UI.Page
    {
        public string destination = "";
        public string hash;
        private string userName;
        public string Verified;
        public string DerivedHash;

        protected void Page_Load(object sender, EventArgs e)
        {
            getParameters();
            Label1.Text = userName;
            
            if (verifyParameters())
            {
                Verified = "Hash Verified";
                FormsAuthentication.SetAuthCookie(userName, true);
                Response.Redirect(destination);
            }
            else
            {
                Verified = "Hash Failed";
            }
        }

        protected void getParameters()
        {
            if (Request.Params.Get("destinationUrl") != null)
            {
                destination = HttpUtility.HtmlDecode(Request.Params.Get("destinationUrl"));
            }
            else
            {
                destination = "/";
            }

            if (Request.Params.Get("uname") != null)
            {
                userName = HttpUtility.HtmlDecode(Request.Params.Get("uname"));
                Label1.Text = userName;
            }
        
            if (Request.Params.Get("hash") != null)
            {
                hash = HttpUtility.HtmlDecode(Request.Params.Get("hash"));
            }

        }

        public bool verifyParameters()
        {
            string message = userName + "|" + destination;
            string CalculatedHash = getHash(message);
            DerivedHash = getHash(message);
            return CalculatedHash.Equals(hash);
        }

        protected string getHash(string message)
        {
            string SECRET_KEY = "HappyCoding";
            HMACSHA1 sha1 = new HMACSHA1(Encoding.Default.GetBytes(SECRET_KEY));
            string CalcultedHash = BitConverter.ToString(sha1.ComputeHash(Encoding.Default.GetBytes(message))).Replace("-", "");
            return CalcultedHash;
        }
    }
}
and this is what my URL looks like when it reaches site2

http://localhost/Login_Website2/Abou...B6C90DD933B5C7
(If you look closely there isn't any value for uname, maybe thats the problem. I am confused).
Any help will be appreciated!





Similar Threads
Thread Thread Starter Forum Replies Last Post
get url values shivakumar BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 1 August 4th, 2010 08:28 AM
Encrypted URL download link benjamr Beginning PHP 1 October 5th, 2008 07:36 PM
Need to fetch distinct records on 2 field values LeoMathew XSLT 17 March 19th, 2008 07:45 AM
Masking parameter values within url. aguivera Pro JSP 5 August 29th, 2006 09:17 AM
Unable to fetch textbox values triveni_sh BOOK: Professional Crystal Reports for VS.NET 0 January 5th, 2006 01:28 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.