Browser back button triggers previous post action in .NET webform application – solved

Recently while working on one of my .NET application I was stuck in a strange problem. I created a button and its click event to insert some entry in database and at the end of this action I used below statement to redirect the page for next step.

Response.Write("<script>top.location="next step page url";</script>");

Note: I used this method to redirect the page because I was doing it in an iframe and wanted to redirect parent page after this step is completed and next step is started. Keep on reading

Send FCM data message & notification to Android, iOS & Web in C#

In my previous article I have explained about types of notification messages in FCM. We have already learnt how to send GCM notification using C#. Now because FCM is replacing GCM so here we are with new sample of working with FCM in C#.

public class NotificationManager
{
	private class NotificationMessage
	{
		public string Title;
		public string Message;
		public long ItemId;
	}
    
	public NotificationManager()
	{
		//
		// TODO: Add constructor logic here
		//
	}

	public string SendNotification(List deviceRegIds, string message, string title, long id)
	{
		string SERVER_API_KEY = "";
		var SENDER_ID = "";
		string regIds = string.Join("","", deviceRegIds);
		
		NotificationMessage nm = new NotificationMessage();
		nm.Title = title;
		nm.Message = message;
		nm.ItemId = id;

		var value = new JavaScriptSerializer().Serialize(nm);

		WebRequest tRequest;
		tRequest = WebRequest.Create("https://fcm.googleapis.com/fcm/send");
		tRequest.Method = "post";
		tRequest.ContentType = "application/json";
		tRequest.Headers.Add(string.Format("Authorization: key={0}", SERVER_API_KEY));

		tRequest.Headers.Add(string.Format("Sender: id={0}", SENDER_ID));

		string postData = "{"collapse_key":"score_update","time_to_live":108,"delay_while_idle":true,"data": { "message" : " + value + ","time": " + """ + System.DateTime.Now.ToString() + ""},"registration_ids":["" + regIds + ""]}";

		Byte[] byteArray = Encoding.UTF8.GetBytes(postData);
		tRequest.ContentLength = byteArray.Length;

		Stream dataStream = tRequest.GetRequestStream();
		dataStream.Write(byteArray, 0, byteArray.Length);
		dataStream.Close();

		WebResponse tResponse = tRequest.GetResponse();

		dataStream = tResponse.GetResponseStream();

		StreamReader tReader = new StreamReader(dataStream);

		String sResponseFromServer = tReader.ReadToEnd();

		tReader.Close();
		dataStream.Close();
		tResponse.Close();
		return sResponseFromServer;
	}
}

You can see that only difference between GCM and FCM code is the request url where we have to post our data and yes this is the only difference between GCM and FCM except another notification message. Keep on reading

Deployment Failed: Unexpected Exception – AWS EBS deployment error

Recently I was trying to deploy my .NET project on AWS Elastic Beanstalk (EBS) using AWS Toolkit for Visual Studio.

Before this deployment attempt this same project was published on same EBS where I was just updating the project after making some changes. But unfortunately I was getting an error message (Deployment Failed: Unexpected Exception) every time I try to deploy the project on my AWS EBS instance and deployment gets failed hence EBS redeployed my previous deployed code again. Keep on reading

[SOLVED] AWS S3 – The authorization mechanism you have provided is not supported

Recently I started working on one of my project which I dropped long ago. I was using AWS SDK in this project as this was planned to deploy on AWS.

When I stopped working on this project that time there was no AWS data center in India (Amazon has launched first data center in India which is located in Mumbai). So when I resumed my project (this time I created all my resources in Mumbai region instead of Singapore) again then I get to know that my code is no more working for AWS S3 operations. Every time I tried to do any S3 operations it shows me this error: Keep on reading

Transferring Cookies from WebBrowser to WebClient

I have prepared many web scrapping application and crawlers. Few of them were developed using WebClient and others were with WebBrowser control of .NET (see my previous article to Get and Set Cookies .NET WebBrowser Control). Recently I got stuck in a situation where I need features of both tools. That is WebClient and WebBrowser.

So my idea was to use WebBrowser control and pass on the session to WebClient when WebClient features are required. Keep on reading

Getting started with Hybrid (iOS, Android, Windows Phone and Windows) App in Apache Cordova and Visual Studio 2015

Microsoft has come up with  very useful tool integration this time in Visual Studio 2015. They have integrated Apache Cordova tools with this version of Visual Studio. You can download it it using online installer. But if you want to download it offline installer get it from my previous article Download Visual Studio 2015 RC offline installer (ISO).

Apache Cordova tools were available separately for Visual Studio 2013 also and you can download the from this link. Keep on reading