My registration tool has a feature which allows candidates to load their personal information (like name, address, ..) from an ID.
When I compile the application with the build-in webserver in VS2010, and press the button to load ID information into textboxes, there is no problem. When I publish it on the localhost (with IIS), it crashes when I press the button.
This is what I received in my event viewer:
0
APPCRASH
Not available
0
w3wp.exe
7.5.7601.17514
4ce7a5f8
KERNELBASE.dll
6.1.7601.17651
4e211319
e0434352
0000b9bc
0
7e796e20-f3e1-11e0-8ea3-60eb69b01829
0
I'm working on a 64-bit laptop, use the Belgium Identity Card SDK.
Here you can find my code for the button;
protected void Button1_Click(object sender, EventArgs e)
{
//READ eID
ClearTextBoxes();
try
{
BEID_ReaderSet ReaderSet;
ReaderSet = BEID_ReaderSet.instance();
BEID_ReaderContext Reader;
Reader = ReaderSet.getReader();
bool bCardPresent = Reader.isCardPresent();
if (Reader.isCardPresent())
{
if (Reader.getCardType() == BEID_CardType.BEID_CARDTYPE_EID
|| Reader.getCardType() == BEID_CardType.BEID_CARDTYPE_FOREIGNER
|| Reader.getCardType() == BEID_CardType.BEID_CARDTYPE_KIDS)
{
try
{
Load_eid(Reader);
}
catch (Exception ex)
{
labelEx.Text = ex.Message;
}
}
else
{
labelEx.Text = "No valid card, please insert a valid IDcard";
}
}
else
{
labelEx.Text = "No IDcard found, please insert your card";
}
BEID_ReaderSet.releaseSDK();
}
catch (BEID_Exception ex)
{
BEID_ReaderSet.releaseSDK();
labelEx.Text = "No valid cardreader found, please connect a valid reader";
}
catch (StackOverflowException ex)
{
BEID_ReaderSet.releaseSDK();
labelEx.Text = "Error: " + ex;
}
catch (OutOfMemoryException ex)
{
BEID_ReaderSet.releaseSDK();
labelEx.Text = "Error: " + ex;
}
}
private void Load_eid(BEID_ReaderContext Reader)
{
try {
BEID_EIDCard card;
card = Reader.getEIDCard();
if (card.isTestCard())
{
card.setAllowTestCard(true);
}
BEID_EId doc;
doc = card.getID();
txtFirstN.Text = doc.getFirstName();
txtLastN.Text = doc.getSurname();
txtDOB.Text = doc.getDateOfBirth();
//CUT GETSTREET IN STREET AND HOUSENO
string street= doc.getStreet();
string[] words = street.Split(' ');
txtStreet.Text = words[0];
txtHouseNo.Text = words[1];
txtPostalCode.Text = doc.getZipCode();
txtCity.Text = doc.getMunicipality();
//sText += "Country = " + doc.getCountry() + "\r\n";
}
catch (Exception ex)
{
BEID_ReaderSet.releaseSDK();
labelEx.Text = "Error: " + ex;
}
}
How can I solve this problem?
Most likely your Application Pool is running under a user which does not have a privilege to access the card reader. This would cause a driver fault which can crash the w3wp.exe process.
Change it to a dedicated user and assign appropriate privileges for this user, or for testing purposes, set it to run under localsys.
Move your code to Javascript (in the browser/html).
I don't think the IIS user has the permission to communicate with the ID reader API.
Related
I have added a CEF control into a WinForm. And I have added an invokeCapture method that is expected to capture the screen shot of the entire page of the CEF. It works fine when first invoking. But errors are encountered since second invoking and more, which the message is "Generated MessageID 100002 doesn't match returned Message Id 100001". How can I capture screen shot more than once?
I have copied the screenshot function code from https://github.com/cefsharp/CefSharp/blob/master/CefSharp.Example/DevTools/DevToolsExtensions.cs to my project and renamed the namespace of it to winformcefdemo.CefSharp.Example.
The variable lastMessageId of the class DevToolsClient, in which class CaptureScreenshot executes ExecuteDevToolsMethodAsync in order to run command "Page.CaptureScreenshot", is private and there are either no getter nor setter to it. It seems to be annoying. The method ExecuteDevToolsMethodAsync would want to compare the message ID of what the method ExecuteDevToolsMethod returns to the automatically increased message ID of the DevToolsClient itself. The DevtoolsClient in the method CaptureScreenShotAsPng is what browser.GetDevToolsClient() returns (in the line 36 of the link above). And I have also checked the implementation of the method GetDevToolsClient. It is also using DevToolsClient devToolsClient = new DevToolsClient(browser); in CefSharp.DevToolsExtensions.
private async void invokeCapture()
{
try
{
byte[] result = await winformcefdemo.CefSharp.Example.DevTools.DevToolsExtensions.CaptureScreenShotAsPng(browser);
// task.Start();
// byte[] result = task.Result;
SaveFileDialog dialog = new SaveFileDialog();
DialogResult dresult = dialog.ShowDialog();
if (dresult == DialogResult.OK)
{
string path = dialog.FileName;
try
{
File.WriteAllBytes(path, result);
MessageBox.Show(path + " saved success");
} catch (Exception e)
{
MessageBox.Show(path + "Unknown error occurred when saving to file: " + e.Message);
}
}
}
catch (Exception ee)
{
MessageBox.Show("Unknown error occurred when capturing: " + ee.Message);
}
}
Solved in Chinese community of CSDN
Use no DevToolsExtensions. Use PageClient Instead. DevToolsExtensions does have issues that are not solved.
And PageClient should be defined globally. Do not define it in the method.
# Source: https://bbs.csdn.net/topics/398544662
CefSharp.DevTools.Page.PageClient pageClien= null;
private async void invokeCapture()
{
if(pageClien==null)
{
pageClien = webBrowser.GetBrowser().GetDevToolsClient().Page;
}
var result = await pageClien.CaptureScreenshotAsync();
if (result.Data != null)
{
MemoryStream ms = new MemoryStream(result.Data);
ms.Write(result.Data, 0, result.Data.Length);
SaveFileDialog dialog = new SaveFileDialog();
dialog.Filter = "PNG Picture (*.PNG)|*.PNG";
DialogResult dresult = dialog.ShowDialog();
if (dresult == DialogResult.OK)
{
string path = dialog.FileName;
try
{
File.WriteAllBytes(path, result);
MessageBox.Show(path + " saved success");
} catch (Exception e)
{
MessageBox.Show(path + "Unknown error occurred when saving to file: " + e.Message);
}
}
}
}
I am attaching a pdf file exported from crystal report. When I use this on development PC it works fine. However when I try on clients PC it gives me an exception
system.io.ioexception the process cannot access the file because it is being used by another process
Here's my code:
private void button1_Click(object sender, EventArgs e)
{
try
{
printbanqoute.ExportToDisk(ExportFormatType.PortableDocFormat, "G:\\" + filename);////For Client PC
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
MailMessage mm = new MailMessage();
try
{
string toemail = BLDashboard.email;
string custnm = BLDashboard.custname;
mm.From = new MailAddress("operations#kaem.in", "Kashif Ahhmed");
mm.To.Add(new MailAddress(toemail, custnm));
mm.IsBodyHtml = true;
string name = BLDashboard.custname;
mm.Subject = "Qoutation ";
String Body = "<div>Hello " + name + ",<br> Thank you for considering us for your next Party/Event, here is the qoute for the Party/Event.<br> If any queries you can reach us at 6096464445. <br> Thank You</div>";
mm.Body = Body;
mm.Attachments.Add(new Attachment("G:\\" + filename));///For Cleint PC
SmtpClient sc = new SmtpClient("smtp.kaem.in");
sc.Credentials = new NetworkCredential("operations#kaem.in", "******");
sc.Send(mm);
MessageBox.Show("Email successfully sent to " + toemail);
}
catch (Exception e1)
{
MessageBox.Show("Unable to send email due to following error:\n\n" + e1.Message, "Email send error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
finally
{
mm.Dispose();//// Later Added this line
}
}
After searching I added
finally
{
mm.Dispose();//// Later Added this line
}
Now it just gave me error no exception.
I tried Disabling and trying, but same issue.
Here's the exception that I am getting:
I want to show a message box on client side When a call is returned from service.
It is confirmed service runs and saves data into Database but call does not return.
I Google it but did not find a way
Here is my client code
private void button1_Click(object sender, EventArgs e)
{
try {
string ide = txt_id.Text;
int id = int.Parse(ide);
string city = txt_city.Text;
Service1Client client = new Service1Client();
if (client.insert(id, city))
{
client.Close();
MessageBox.Show("Your changes were saved");
}
}
catch(Exception ex)
{
Console.WriteLine(ex);
}
}
Service code
public bool insert(int id,string city)
{
Ship s = new Ship
{
order_id = id,
shipcity = city,
order_date = DateTime.Now
};
ShipsDataContext od = new ShipsDataContext();
od.Ships.InsertOnSubmit(s);
try
{
od.SubmitChanges();
Console.ReadKey();
return true;
}
catch (Exception ex)
{
Console.WriteLine(ex);
return false;
}
}
You are waiting for console input:
Console.ReadKey();
Btw, that error handling is a problem because you are suppressing bugs (by discarding all error information) and in case of error you do nothing.
When checking the user against active directory, I also check their mail attribute try to store it into a session variable
However, when the users AD account doesn't have a mail address, I would like to display this on the screen for them.
At the moment an exception is caught for index out of range
How can I can check for this so that I can set the label property? I obviously want to avoid setting it in the catch.
try
{
var mail = adsSearchResult.Properties["mail"][0] ;
if (mail == null)
{
Label3.Text = "blablabla";
return;
}
else
{
Session["email"] = adsSearchResult.Properties["mail"][0].ToString().ToLower();
}
}
catch (Exception ex)
{
Response.Write(ex);
}
You simply could add null and length check, you should actually if there is such possibility.
try {
if (adsSearchResult.Properties["mail"]!= null && adsSearchResult.Properties["mail"].Any()) {
var mail = adsSearchResult.Properties["mail"][0];
if (mail == null) {
Label3.Text = "blablabla";
return;
} else {
Session["email"] = adsSearchResult.Properties["mail"][0].ToString()
.ToLower();
}
}
} catch (Exception ex) {
Response.Write(ex);
}
I've recently converted a TCP-port listening application into a Windows Service, which installs and runs perfectly on my 32bit Vista laptop.
The problem was, after its installation, which works, I attempted to run the service(through Remote Dekstop) on a 64bit Win7 and it neatly handed me an error 1053, basically stating that the service timed out while starting up.
Now I've gotten it to start up without errors, but all it does is exit immediately without any errors or any eventLogging past OnStart.
I've tried replacing my Timer with Threading to see if that might have been the issue with the strange start, but no luck there... Here's the OnStart method of the service and the method that is meant to run continously.
protected override void OnStart(string[] args)
{
myServer.Start();
eventLog1.WriteEntry("Server started.");
mWorker = new Thread(StartUp);
eventLog1.WriteEntry("Starting up CykelScore service.");
mWorker.Start();//Start the service
//timer.Start(); // Start the timer
}
private void StartUp(object arg)
{
while (true)
{
eventLog1.WriteEntry("Running.");
if (mStop.WaitOne(10000)) return;
{
if (Monitor.dataCount > 0)
{
string tmp = "";
eventLog1.WriteEntry("Antal tags: " + Monitor.dataCount.ToString());
lockedUp.WaitOne();
try
{
tmp = Monitor.PopData();
}
catch (Exception ex)
{
eventLog1.WriteEntry("Fejl:" + ex.ToString());
}
eventLog1.WriteEntry("Recieved: " + tmp);
string buffer = tmp;
string antenna = (buffer.Split(',')[0]).Replace(" ", "");
string time = buffer.Split(',')[2];
string RFIDNR = (buffer.Split(',')[1]).Replace(" ", "");
string[] ART = new string[3];
ART[0] = antenna;
ART[1] = RFIDNR;
ART[2] = time;
if (lastreceivedtagID == RFIDNR)
{
eventLog1.WriteEntry("Same tag as last time. No need to check database");
}
else
{
if (!DataHandler.LoggedInCurrentTimespan(ART))
{
try
{
DataHandler.SaveToLocal(ART);
eventLog1.WriteEntry("Data saved to local database");
DataHandler.SendToRemote(tmp, Monitor.server, Monitor.database, Monitor.username, Monitor.password);
eventLog1.WriteEntry("Data sent to remote database");
}
catch (Exception ex)
{
eventLog1.WriteEntry("Fejl" + ex.ToString());
}
}
else
eventLog1.WriteEntry("Discarding data. Already in local database");
}
lastreceivedtagID = RFIDNR;
lockedUp.ReleaseMutex();
}
}
}
}
Does anyone have any idea what might be the issue?