1

I developed a card reader application using ASP.net MVC5. The card reader used by is HID OMNIKEY 3121. When the card is inserted this application will read the name,gender,dob etc that is encoded in the chip. This is working fine in my local system and I am able to show it in a view. Then I publish the same to IIS in a server. Then I call the MVC website from my local(client) system. The card reader is connected to the local system but when click the read data it is giving a blank page.

Any configuration issue? Please guide me

Edited Controller

public class cardController : Controller
    {

        public ActionResult Index()
        {
            try
            {

             ReaderManagement readerMgr = new ReaderManagement();
             readerMgr.EstablishContext();//extablishing card connection API


                try
                {
              readerMgr.DiscoverReaders(); //discover card reader connected
                }
                catch(Exception ex)
                {
                    return RedirectToAction("Nocard", "card");
                }
                PCSCReader[] readers = readerMgr.Readers;
                PCSCReader selectedReader =             readerMgr.SelectReaderByName(readers[0].ReaderName);
                //Other select methods may be called...
                selectedReader.IsConnected();
      IDCardWrapper.LoadConfiguration();


                bool IsCardConnected = selectedReader.IsConnected();
                bool isContactless;
     if (IsCardConnected) isContactless =     selectedReader.IsContactless(); 
                if (!IsCardConnected)
                {
                    readerMgr.SelectReaderByName(readers[0].ReaderName);

                    try
                    {
                        selectedReader.Connect(readerMgr.Context);
                    }
                    catch(Exception ex)
                    {
                       return RedirectToAction("Nocard", "card");
                    }

                }


                CardInfo cardInfo = selectedReader.GetCardInfo();

                try
                {

 PublicDataFacade publicDataFacade = selectedReader.GetPublicDataFacade();
 CardHolderPublicData publicData = publicDataFacade.ReadPublicData(true, true, true, true, false);
ViewBag.sex = PublicDataUtils.GetSex(Utils.ByteArrayToUTF8String(publicData.Sex));
ViewBag.maritalstatus = PublicDataUtils.GetMaritalStatus(Utils.ByteArrayToHex(publicData.MaritalStatus, ""));
                    ViewBag.sponsortype = PublicDataUtils.GetSponsorType(Utils.ByteArrayToHex(publicData.SponsorType, ""));

                    ViewBag.dob = Utils.ByteArrayToStringDate(publicData.DateOfBirth);

                    ViewBag.fullname = PublicDataUtils.RemoveCommas(Utils.ByteArrayToUTF8String(publicData.FullName));
                    ViewBag.arabicname = PublicDataUtils.RemoveCommas(Utils.ByteArrayToUTF8String(publicData.ArabicFullName));


                }


                readerMgr.CloseContext();
            }
            catch (Exception ex) //(MiddlewareException ex)
            {

            }

            return View();
        }

View

Simply show the viewbag data assigned.

Dravid
  • 21
  • 3
  • You need to include some code, perhaps its trying to read a card read on the server not the client. No code, no clue! – Ashley Medway Aug 27 '15 at 09:01
  • @AshleyMedway question edited..ya may be its trying to read a card on the server not the client..how to make it to read client side..im stucked there – Dravid Aug 27 '15 at 09:16
  • 1
    Thanks Dravid, I am not an expert on this technology but unless it has some kind of sockets connection to the client, which it doesn't look like it does. It is as I suspected, your code is trying to read details from a card reader on the server. At the very least if there was some connection to the client I would expect you to be doing something with the request context. – Ashley Medway Aug 27 '15 at 09:20
  • @AshleyMedway thanks for the guidens..let me check – Dravid Aug 27 '15 at 09:21
  • Short version is that no normal web page can access local peripherals and code run on the server would access peripherals local to the server. You either need to write a small desktop app that talks to the reader and can be accessed locally via Javascript/Ajax from the webpage, or don't use a standard browser (eg [.hta's](https://en.wikipedia.org/wiki/HTML_Application) used to launch a chromeless IE window with additional local permissions, including the ability to make calls using COM). Alternatively, Flash may allow you to skip the browser security model and access a local device – Basic Aug 27 '15 at 09:26
  • Java applet is another option, but java is slowly leaving the browsers (or browsers are leaving java :) ) – vlp Nov 02 '15 at 20:44
  • @Dravid Same issue for me too. Have you got the solution? – Ashin Jan 22 '18 at 10:31

1 Answers1

0

You can't access a local device (like a smart card reader) form a web site.

You'll have to install a desktop application on the client computer (as stated by @Ashley and @Basic) : Chrome App or Windows App for instance.

Supersharp
  • 29,002
  • 9
  • 92
  • 134