A Place for C Sharpers/.Netters

I Will do coding till last moment of life-Kiran Patil

Posts Tagged ‘ASP.NET’

Access Internet/Local Website from Your Windows Mobile Device Emulators

Posted by kiranpatils on November 19, 2009

Challenge

If you want to access any website Or You want your locally developed mobile application/web application to be viewed in Windows Device Emulator then you are at the right post.

Solution
  1. Download ActiveSync and install on your local machine where you would like to run Emulator. How to setup ActiveSync?
  2. Open Visual Studio and click on Tools | Connect to Device:

clip_image002

  1. Select Device emulator to run and say connect.

clip_image004

  1. It will open your device emulator:

clip_image006

  1. Verify that ActiveSync is up and running by its symbol in Notification Area.

clip_image008

  1. Open Device Emulator Manager

clip_image010

  1. Currently running Device Emulator Manager will be shown in Green.

clip_image012

  1. Right click and say “Cradle”

clip_image014

  1. As you click on Cradle ActiveSync window will popup. Select Guest Partnership[Or better do cancel it will by default to Guest Mode]. If your Emulator got synced with ActiveSync then Notification Icon will go Green.
  1. Now you are ready to access website.
    1. Internet – Enter your URL.

clip_image016

    1. Local – To Access your Local Website which is running on Cassini(Development Web Server). To access it you need to access it by IP ADDRESS:PORTNUMBER. Please note that you can’t access it by localhost:PORTNO Because localhost points to Emulator’s localhost and it will never go to your machine. You have to see both Emulator and your local machine as a two different devices even though they are running on same machine.

clip_image018

If this blog helped you. Say a big thanks to my friends who always give me a shout whenever they found something challenging like this and inspire me to learn a new things which finally inspires me to pen down on my blog and share with you :)

Happy Emulating!

Webliography

Setup ActiveSync

Nice blog – Thanks to this blog

If you have Windows Vista or Later

Accessing Device Emulator Without ActiveSync

Feedback

Posted in ASP.NET, Windows Mobile | Tagged: , , | Leave a Comment »

How to delete Cookie?

Posted by kiranpatils on June 3, 2009

Challenge:

Today, i was implementing Remember Me Functionality in one of my application. I know you know what is “Remember Me” functionality. But when user says “Signout” i need to Forgot the user and to do that i need to delete my Cookie which i persisted when user says “Remember Me”..So, you will say simple delete cookie..But sorry sir you can’t delete cookie because it is on client side and user/browser can delete it..So, shall we ask user to delete cookie?? no we should not..then we just have one friend left “Browser”. But we need to cheat our friend[I strongly discourage cheating a real friend in real life :) ]. We don’t have any method by which we can delete the cookie directly but we can delete it..Want to know how??

Solution:

Okay, Boss relax!!! Here is the solution you should set the cookies Expiry date to past date..So, whenever Browser will see that it is expired it will discard that cookie.. I have created one method which you can directly use using Control Inheritance[COPY-PASTE] :) .. in which you just need to pass Cookie’s name rest smart method will manage :)

Here it is:

public static void RemoveCookie(string key)
{
//get cookie
HttpCookie cookie = null;
if (HttpContext.Current.Request.Cookies[key] != null)
{
cookie = HttpContext.Current.Request.Cookies[key];
//You can't directly delte cookie you should
//set its expiry date to earlier date cookie.Expires = DateTime.Now.AddDays(-1);
//Add expired cookie back to response - send to browser
HttpContext.Current.Response.Cookies.Add(cookie);
}
}

Posted in ASP.NET | Tagged: , | Leave a Comment »

How to Create ASP.NET web Service and how to consume it: A Beginner’s Guide

Posted by kiranpatils on April 23, 2008

Creating this post especially for my friend. Who want to learn How to create His First Web Service. If you too want to do the same then go ahead and start your visual studio.

Service

  1. Click on Web Site Project

  2. It will open New Web site Dialog box. Choose ASP.NET web service and give it appropriate name(HelloWorldService) and select your Coding language(C#). Click OK.

    It will take some time because it will make everything ready for you sir. So, you can start quickly

  3. What it has created?

    Service.cs: is the main file where you can write you code. E.g application logic etc..Calling Data Access layer etc.

    Service.asmx will expose your service to outer world.

  4. Web Method

    If you will see Service.cs it has one method already written. You can use it as a reference implementation

[WebMethod]

public
string HelloWorld() {


return
“Hello World”;

}

Any method you want to expose you have to declare it by attribute WebMethod

Let’S create our new method.So, you can get more into methods.

Just copy paste above one and modify it will like this:

///
<summary>


/// This method will take argument as a string and show it with greeting


///
</summary>


///
<param name=”name”></param>


///
<returns></returns>

[WebMethod]


public
string
MyHelloWorld(string name)

{


return
“Hello World,”+name;


//Here you can call your Insert,Update,Delete from DAL and write return statement

}

  1. Build Web Site [CTRL+SHIFT+B]. That’s it we have our service Ready. Let’s create one consumer for it.

Consumer

Our Service is ready. It will take name and return it with Hello World name. I am creating here one Windows application for demo. You can create any client to use it.[That's why it is service :) ]

1. Click on your solution file name Means [Your focus should be on C:\HelloService or your solution name]

2. Select File | Add | New Project

3. It will open Add New Project Dialog Box. Select Windows application and give appropriate name to it. Click OK

4. So now you will have structure as under:

5. Right Click on HelloWorldConsumer project and Click on Add Web Reference- For Adding service reference.

6.It will open Add Web Reference window. Just click on Web Services in this solution. Because we have our service under same solution.

7. It will find out service. Just click on it.

8. It will load our methods as shown here: [Web reference name I had changed "localhost" to "HelloWorldClient". So you should also do it. Its good practice]. Click on Add reference button. – Which will add our service reference to client.

9. Now your soln structure should look like:

10. Click on Form1 and drag some controls so we can test it. So, your form should look like this.

11. Double click on “Call Service” Button it is Buttton1 for me. For creating its Click event handler code. And it will point it to handler code call your service here and show result in Messagebox as shown here.

12. Build solution. And ensure that HelloWorldConsumer-windows application is your startup project. Then run the project [CTRL+F5]

13. looks Cool… It’s working man. Try with your name and enjoy!!!

Links:

http://quickstarts.asp.net/QuickStartv20/webservices/

http://www.w3schools.com/webservices/default.asp

Happy Service Coding!!!

I have also kept solution here for reference. But I request you first try yourself and if get some error then and then try this. Pls try to do it yourself first. you can download it from Here

Update:

Add Reference in VS 2008 — http://www.carlosfemmer.com/post/2008/01/How-to-add-web-reference-in-VS-2008-Project.aspx

Thanks to Ravindra Joshi for pointing it out!

 

Posted in ASP.NET | Tagged: | 12 Comments »

ASP.NET TEMP ERROR While Building+WCSF/General ASP.NET

Posted by kiranpatils on February 8, 2008

from last few days when we are implementing WCSF. we are facing some errors which are really not ours..it is of TEMP files generated by ASP.NET.

Problem:

Suppose i have one Interface named as IEmployee and it has 3 members EmpName,EmpID,EmpAddress and one of my page let’s say Employee.aspx implements it so it looks like this:

Employee.aspx:IEmployee

{

//Three Members implemented

}

now i build and it shows “Build Succeeded” .

after sometime i think that i don’t need “EmpID” in interface so i delete it and also deleted its implementation from Employee.aspx and now when i Build it. it shows me error and when i click on it it points to me ASP.NET Temp files location. which are not mine. [For your knowledge i want to say that ASP.NET Generates Temporary files at C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\<Web site name>]. so it will point you there. But as i think it should work fine……..for that i have to work around it for hours and hours..so want to know its solution???

Stack Trace:

Error:
Error 126 ‘Employeet’ does not implement interface member ‘IEmployee.EmployeeID’ c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\developmentwebsitea97a19d\326f353\App_Web_euqzzc2o.0.cs 14

Solution:

For solving this error just follow me:

1.Take Copy/Backup of Employee.aspx page.

2.Now Delete if from WebSite Solution.
3.Now Build Solution. [you will not found that error]

4. Now add that page again from Backup path.

5. Now Build it and That’s it…..You have killed the errors successfully.

Enjoy ASP.NET!!

-Kiran Patil

Posted in ASP.NET, Web Client Software Factory | Tagged: | 2 Comments »