Get the name and value of all cookies - asp.net

I'm trying to get all cookies and so far found nothing using Google and other topics.
What I have tried so far:
If (Request.Cookies().Count > 0) Then
sss.Visible = True
sss.InnerHtml = Request.Cookies().Count
End If
I can get the Cookies().Count and return a number, but my goal is get the name and value of all cookies. I have no idea what I should use. I'm good in PHP but forced to do this via .NET and can't find something like var_dump($_COOKIE); in VB.NET. Any ideas?

If (Request.Cookies.Count > 0) Then
sss.Visible = True
Dim i as Ingeter
For i = 0 To (Request.Cookies.Count - 1)
sss.InnerHtml = sss.InnerHtml + Request.Cookies.Get(i).Name + " = " + Request.Cookies.Get(i).Value + vbCrLf
Next
End If

Related

google api .net client v3 getting free busy information

I am trying to query free busy data from Google calendar. Simply I am providing start date/time and end date/time. All I want to know is if this time frame is available or not. When I run below query, I get "responseOBJ" response object which doesn't seem to include what I need. The response object only contains start and end time. It doesn't contain flag such as "IsBusy" "IsAvailable"
https://developers.google.com/google-apps/calendar/v3/reference/freebusy/query
#region Free_busy_request_NOT_WORKING
FreeBusyRequest requestobj = new FreeBusyRequest();
FreeBusyRequestItem c = new FreeBusyRequestItem();
c.Id = "calendarresource#domain.com";
requestobj.Items = new List<FreeBusyRequestItem>();
requestobj.Items.Add(c);
requestobj.TimeMin = DateTime.Now.AddDays(1);
requestobj.TimeMax = DateTime.Now.AddDays(2);
FreebusyResource.QueryRequest TestRequest = calendarService.Freebusy.Query(requestobj);
// var TestRequest = calendarService.Freebusy.
// FreeBusyResponse responseOBJ = TestRequest.Execute();
var responseOBJ = TestRequest.Execute();
#endregion
Calendar API will only ever provide ordered busy blocks in the response, never available blocks. Everything outside busy is available. Do you have at least one event on the calendar
with the given ID in the time window?
Also the account you are using needs to have at least free-busy access to the resource to be able to retrieve availability.
I know this question is old, however I think it would be beneficial to see an example. You will needed to actually grab the Busy information from your response. Below is a snippet from my own code (minus the call) with how to handle the response. You will need to utilized your c.Id as the key to search through the response:
FreebusyResource.QueryRequest testRequest = service.Freebusy.Query(busyRequest);
var responseObject = testRequest.Execute();
bool checkBusy;
bool containsKey;
if (responseObject.Calendars.ContainsKey("**INSERT YOUR KEY HERE**"))
{
containsKey = true;
if (containsKey)
{
//Had to deconstruct API response by WriteLine(). Busy returns a count of 1, while being free returns a count of 0.
//These are properties of a dictionary and a List of the responseObject (dictionary returned by API POST).
if (responseObject.Calendars["**YOUR KEY HERE**"].Busy.Count == 0)
{
checkBusy = false;
//WriteLine(checkBusy);
}
else
{
checkBusy = true;
//WriteLine(checkBusy);
}
if (checkBusy == true)
{
var busyStart = responseObject.Calendars["**YOUR KEY HERE**"].Busy[0].Start;
var busyEnd = responseObject.Calendars["**YOUR KEY HERE**].Busy[0].End;
//WriteLine(busyStart);
//WriteLine(busyEnd);
//Read();
string isBusyString = "Between " + busyStart + " and " + busyEnd + " your trainer is busy";
richTextBox1.Text = isBusyString;
}
else
{
string isFreeString = "Between " + startDate + " and " + endDate + " your trainer is free";
richTextBox1.Text += isFreeString;
}
}
else
{
richTextBox1.Clear();
MessageBox.Show("CalendarAPIv3 has failed, please contact support\nregarding missing <key>", "ERROR!");
}
}
My suggestion would be to break your responses down by writing them to the console. Then, you can "deconstruct" them. That is how I was able to figure out "where" to look within the response. As noted above, you will only receive the information for busyBlocks. I used the date and time that was selected by my client's search to show the "free" times.
EDIT:
You'll need to check if your key exists before attempting the TryGetValue or searching with a keyvaluepair.

asp.net RowFilter comparing string with int

Im having an issue with this , Im new to asp.net and really dont have much understanding with their syntax, I do understand the error but have no idea how to implement a fix:
ProductTable.RowFilter = "ProductID ='" & ddlCategory.SelectedValue & "'"
The error im recieving is : cannot perform '=' operation on system.int32 and system.string data view
my productID data type is : int;
Now i dont see how im comparing a string vs int, ddlCatergory selected index would also return a value... besides the point...im completely stuck.
any help is appreciated.
Using windows 8, VS 2012 , SQL database.
ddlCategory.SelectedValue is likely to be string given the SelectedValue attribute of the drop down list is a string, you are also assigning it as a string e.g. the filter value could end up being something like "ProductID ='123'" where 123 is the SelectedValue.
Assuming that SelectedValue is never null or empty I would use something like:
ProductTable.RowFilter = string.format("ProductID = {0}", ddlCategory.SelectedValue);
If it could be empty then I would do something along these lines:
if(string.IsNullOrEmpty(ddlCategory.SelectedValue))
{
ProductTable.RowFilter ="";
}
else {
ProductTable.RowFilter = string.format("ProductID = {0}", ddlCategory.SelectedValue);
}
OR
int tempInt;
if(int.TryParse(ddlCategory.SelectedValue,out tempInt))
{
ProductTable.RowFilter = string.format("ProductID = {0}", tempInt);
}
I've written the above in C# (not syntax checked though sorry!) though it would be easy enough to convert it to VB if necessary.
You should try by removing single quotes after = sign, so it give something like this
ProductTable.RowFilter = "ProductID = " + ddlCategory.SelectedValue

ASP.NET VB - Conversion from type 'DBNull' to type 'String' is not valid

I have the following ASP.NET (VB) code:
strLocation = CStr(q1("LocationName")) + " " + CStr(q1("LocationAddress")) + " " + CStr(q1("LocationCity"))
As LocationCity is null:
I get Conversion from type 'DBNull' to type 'String' is not valid.
Is there a way to fix this.
If it was only LocationCity I would probably do something like:
If IsDBNull(q1("LocationCity")) Then
strLocation = ""
Else
strLocation = CStr(q1("LocationCity"))
End If
I also tried:
strLocation = If(CStr(q1("LocationName")), "") + " " + If(CStr(q1("LocationAddress")), "") + " " + If(CStr(q1("LocationCity")), "")
but got the same result
In C# I would normally use ?? but not sure of the best approach in ASP.NET VB
The equivalent to the C# ?? in VB.NET is the IF Operator
strLocation = If(IsDBNull(q1("LocationCity")), "", CStr(q1("LocationCity")))
Do not use the IIF Function as it is deprecated, doesn't support short circuiting and is not type safe.
Also see Is there a VB.NET equivalent for C#'s ?? operator? for related information
You could use If(IsDBNull(q1("propertyName")), "", CStr(q1("propertyName")))
Or you could implement the code block you showed as a method and call that method for each property. IMO, it would make your line of code much cleaner than using 3 IIF statements
Function StringValue(q1 as Q1Type) as String
If IsDBNull(q1("LocationCity")) Then
Return ""
Else
Return CStr(q1("LocationCity"))
End If
End Function
strLocation = StringValue(q1("LocationName")) + " " + StringValue(q1("LocationAddress")) + " " + StringValue(q1("LocationCity"))

LINQ-to-SQL anonymous types problem with null value

I have some problems with LINQ-to-SQL and anonymous types.
I have gridview (it's not that important, but it is Telerik's RadGrid) which has the following datasource:
TSEntities db = new TSEntities();
int idFirma = Convert.ToInt16(Request.QueryString["idt"]);
var ticketList = (from t in db.Ticket
where t.idFirma == idFirma
select t).ToList();
gvTicketi.DataSource = from t in ticketList
where t.idFirma == idFirma
orderby t.idTicket, t.RedniBroj, t.DatumPrijave
select new { t.idTicket, t.idFirma, t.idKontakt, t.idManager, t.idNadredeniTicket, TicketNumber = t.idNadredeniTicket + "-" + t.RedniBroj, t.Biljeske, t.DatumDo, t.DatumPrijave, t.OpciPrioritet, t.Opis, t.OpisZatvoren, t.Prioritet, t.Status, t.Tip, t.VrstaPrijave, t.Zatvoren, NazivKontakta = t.Kontakt.Ime + " " + t.Kontakt.Prezime };
Everything works fine when NazivKontakta isn't null, but when is null everything crashes with the following error: "Object reference not set to an instance of an object" which explains everything, but doesn't help me to work it out.
What I'd like to do (if possible) is to somehow check for the null value and if it is null I'd like to set "NazivKontakta" to string value "Empty" and if it's not null value to set it to the values from the database.
Is there a a solution for this? Any help would be appreciated!
Thank you in advance!
I suspect it's actually this which is causing the problem:
t.Kontakt.Ime + " " + t.Kontakt.Prezime
i.e. not NazivKontakta being null, but t.Kontakt being null. After all, if nothing's dereferencing NazivKontaka, there shouldn't be a problem.
Try this in your query:
NazivKontakta = t.Kontakt == null ? "" : t.Kontakt.Ime + " " + t.Kontakt.Prezime
Try
NazivKontakta = t.Kontakt =! null ?
t.Kontakt.Ime + " " + t.Kontakt.Prezime :
string.Empty
I would write a simple IsNull function or use IsDBNull to check and if it is null return string.Empty

ASP.NET: Execute an external executable doesn't work

I need help with the code below.
I try to convert a AutoCAD file from the format dwg to the format dwf.
Then, the dwf file is downloaded and opened on the client computer using a java applet.
The command used to convert the dwg file on the command-line is:
C:\inetpub\wwwroot\COR-Basic\cadviewer\converter\ax2008.exe -i="C:\inetpub\wwwroot\test\container\DU38_EG00_070116.dwg" -o="C:\inetpub\wwwroot\COR-Basic\cadviewer\files\DU38_EG00_070116.dwf" -f=dwf -model -text
this works when I enter the command text in cmd.exe.
But when I call it from my asp.net application, it only starts the process, but the process never ends...
I've tried adding an additional user, have given this user full permission, and full permissions on wwwroot, but it still doesn't work.
Anybody knows what I'm doing wrong, or how I could do it in another way?
If System.IO.File.Exists(strDWGlocation) Then
Dim psiProcessSettings As Diagnostics.ProcessStartInfo = New Diagnostics.ProcessStartInfo
psiProcessSettings.FileName = strApplicationPath
psiProcessSettings.Arguments = " -i=""" & strDWGlocation & """ -o=""" & strOutputLocation & """ -f=dwf -model -text"
'ST-LAPTOP\converter
psiProcessSettings.UserName = "converter"
psiProcessSettings.Password = secureString
'StefanSteiger.Debug.MsgBox("Input location:" + strDWGlocation)
'StefanSteiger.Debug.MsgBox("Output location:" + strOutputLocation)
Response.Write("<h1>Argument1: " + psiProcessSettings.Arguments + "</h1>")
Response.Write("<h1>Pfad1: " + psiProcessSettings.FileName + "</h1>")
'psiProcessSettings.RedirectStandardInput = True
psiProcessSettings.RedirectStandardError = True
psiProcessSettings.RedirectStandardOutput = True 'Redirect output so we can read it.
psiProcessSettings.UseShellExecute = False 'To redirect, we must not use shell execute.
'psiProcessSettings.CreateNoWindow = True ' don't create a window
Dim pConverterProcess As Diagnostics.Process = New Diagnostics.Process
pConverterProcess = Diagnostics.Process.Start(psiProcessSettings) 'Create the process.
pConverterProcess.Start() 'Execute the process.
'Response.Write("<h1>" + Replace(pConverterProcess.StandardOutput.ReadToEnd(), vbCrLf, "<BR />") + "</h1>") 'Send whatever was returned through the output to the client.
'pConverterProcess.CancelOutputRead()
'pConverterProcess.CancelErrorRead()
'pConverterProcess.StandardInput.Close()
'Wait for the process to end.
'pConverterProcess.WaitForExit()
pConverterProcess.Close()
'Dim iExitCode As Integer = pConverterProcess.ExitCode()
pConverterProcess.Dispose()
Else
MyNamespace.Debug.MsgBox("No such file.")
End If
This is my code that does a similar thing, and it works!
process.StartInfo.FileName = toolFilePath;
process.StartInfo.Arguments = parameters;
process.StartInfo.UseShellExecute = false; // needs to be false in order to redirect output
process.StartInfo.RedirectStandardOutput = true;
process.StartInfo.RedirectStandardError = true;
process.StartInfo.RedirectStandardInput = true; // redirect all 3, as it should be all 3 or none
process.StartInfo.WorkingDirectory = Path.GetDirectoryName(toolFilePath);
process.StartInfo.Domain = domain;
process.StartInfo.UserName = userName;
process.StartInfo.Password = decryptedPassword;
process.Start();
output = process.StandardOutput.ReadToEnd(); // read the output here...
process.WaitForExit(); // ...then wait for exit, as after exit, it can't read the output
returnCode = process.ExitCode;
process.Close(); // once we have read the exit code, can close the process
Why have you commented out the WaitForExit()?
You could try setting EnableRaisingEvents to true as well.
In my experience, the Process class is quite difficult to work with when reading the standard output, try removing any code that attempts to redirect and read output

Resources