|
The HTML code one gets often depends on the device the client uses (e.g. large desktop vs small mobile phone), therefore setting a reasonable useragent is pretty important, as Richard already told you.
Example: my desktop Windows10/Chrome browser uses this user-agent (a single rather long line of text):
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.138 Safari/537.36
|
|
|
|
|
Sometimes, when you have an exception on your code, that is catched and rethrown and that you press F5 (continue) the debugger will stop stop obstinately several times in a row in the same spot (I found that more prevalent in Web application) and you have to press F5 F5 F5.... but not too many times because, sometimes, the 8th or 9th time is in another relevant user method...
Is there a way to have the debugger stop on all exception, but skip some method altogether?!
I tried to decorate my relevant method with
[System.Diagnostics.DebuggerHidden]
[System.Diagnostics.DebuggerStepThrough]
[System.Diagnostics.DebuggerNonUserCode]
[System.Diagnostics.DebuggerStepperBoundary]
The closest I was to something was with DebuggerHidden , but it still stops like 8 or 9 times on my method (it's an ExceptionFilter ), just not select it...
modified 17-May-20 20:41pm.
|
|
|
|
|
When I start a new Windows Forms project in Visual Studio it always places the form at the upper left of the screen which seems stupid to me to put it there.
I'm looking for a way to move it to center screen.
As far as I know adjusting the Properties only affects run-time position of the form.
|
|
|
|
|
This is not a programming issue. You need to talk to Microsoft, it's their product.
|
|
|
|
|
I had to check this out, and I see the same thing.
But to me it seems quite natural. When I create a new text file, I start writing in the upper left hand corner, too.
All sorts of boes and forms, frames and whatever to be filled in, I feel it natural to fill left to rigth, top to bottom. If I want to drag a box larger, I alway drag the lower right corner (so the old contents stays in the same positions, unless it is flowing, of course.
Personal taste varies. But I am starting to ask myself why the window is centered when you work with a WPF app. I think upper left would be better.
|
|
|
|
|
Were you looking for the StartPosition property of your form? You can set that to "CenterScreen".
|
|
|
|
|
That only affects what your form looks like when you're at run-time. I was wondering if I can get the form positioned closer to the center of the screen at design-time, but I don't think that can be changed.
|
|
|
|
|
No, you can't.
If you want that, switch to WPF, but you're going to have to rewrite your entire app to do that.
|
|
|
|
|
I can see good reasons to switch to WPF, but this is not one of them.
|
|
|
|
|
class B
{
public int z = 3;
public string s = "bbb";
}
class A
{
public int[] x = { 1, 2 };
public string str = "asdf";
public float y = 2.0f;
public B b = new B();
}
How to get list of all variables and their values for entity A a = new A() using C# Reflection ?
|
|
|
|
|
The variables are known as fields. If you do Type.GetFields for the type, you get the list of fields returned as a FieldInfo array. So, if you wanted a list of all public or static fields (as an example), you could write something like this (this is a generic method to do this):
public static class MetadataInfo
{
public static FieldInfo[] GetFields<T>()
{
return typeof(T).GetFields(BindingFlags.Public | BindingFlags.Static);
}
}
|
|
|
|
|
I used this part of code, but it is not work for:
int[] x and for internal class B b (see my example).
Now I use the following:
string output = JsonConvert.SerializeObject(a); // Newtonsoft.json
But I want to use C# reflection.
|
|
|
|
|
Works for me.
public static void Main()
{
A a = new A();
FieldInfo[] fi = MetadataInfo.GetFields<A>();
int[] x = (int[])fi[0].GetValue(a);
Console.WriteLine(x[0]);
}
The knack is the cast; if you know what type to expect, then you can simply cast. If you don't know the type, then you have to get the fields of that object and inspect those. May require recursion if you have a lot of nested unknown objects.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
"If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.
|
|
|
|
|
|
Thank you, it works fine! 
|
|
|
|
|
Hi,
I would like to show radio buttons of multiple choices in property grid, is there any way i can do that?
|
|
|
|
|
Maybe, but I don't know how to do that. Using a dropdown for multiple-choice is relatively easy though, maybe that's OK as an alternative?
|
|
|
|
|
Yes. Anything you can host on a form, can be shown inside a dropdown editor.
PropertyGrid and Drop Down properties[^]
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
"If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.
|
|
|
|
|
In a simple web application I have:
TryUserName = Environment.GetEnvironmentVariable("UserName");
LogonServer = Environment.GetEnvironmentVariable("LogonServer");
YourDomainName = Environment.GetEnvironmentVariable("UserDomainName");
During development I have a VPN open to the server which is called NZ-SP-AP1.
On my home machine set gives me:-
Username = Ormond
No LogonServer or UserDomainName.
On the server, logged in as Administrator, set gives me:-
Username = Administrator
LogonServer = \NZ-SP-DC1 (correct)
No UserDomainName.
When I open the web page on the server with the variables in a textbox, I get:-
TryUserName = NZ-SP-AP1$
LogonServer is blank.
UserDomainName is blank.
Does anyone know where it gets these values, particularly the Username?
|
|
|
|
|
|
Anticipating your next question: no, there is no way for a website to obtain these details from a user's computer. If there were, that would be a security vulnerability.
If this is an intranet site, and your users are all part of the same domain/forest as the web server, you might be able to use Windows authentication on your site. Depending on their browser settings, they would either automatically log in as themselves, or have to enter their Windows username and password to log in.
Windows Authentication <windowsAuthentication> | Microsoft Docs[^]
If this is an internet site, where your users are not part of your domain, then you cannot obtain any information about their user account.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
ASP.NET code runs entirely on the server, never on the client or in the browser.
Your code is running on the web server under a service account, so the user information you get back is going to be for the user account the web server is running your code under.
No, there is no way to get the code your wrote to work on the client machine.
|
|
|
|
|
Write program to determine if a given sentence is palindrome or not
User Array-based Stack, and Linked-based Queue in your program.
Class Stack:
Write class Stack using array with the following attributes and methods:
Attribute array (items) of 100 char.
Attribute (top) of type integer.
Constructor (Stack), and initialize (top) to -1.
Method (empty), which returns true if the stack is empty.
Method (push), which takes a character value and push it into the stack.
Method (pop), which returns the last value in (Last-In-First-Out).
Class Node and class Queue:
Write class Node with two attributes; data of type character, and next of type Node. Write a set and get methods for each attribute.
Write class Queue using Linked List with the following attributes and methods:
Attributes (Front and Rear) of type Node.
Constructor (Queue), and initialize all attributes to Null.
Method (empty), which returns true if the queue is empty.
Method (insert), which takes a character value, create object of node, save the character in it, and insert it into the queue.
Method (remove), which returns the first value in (First-In-First-Out).
Palindrome Algorithm in Main:
Create a stack and a queue
Ask user to enter a string
Read string and store it in string s
set variable (pal) of bool to true
Repeat for each character in s:
push s[i] in stack
Insert s[i] in queue
Start new Loop, until stack is empty:
x = stack.pop();
y = queue.remove();
if ( x != y ) set (pal) to false and break from loop
Now, if pal is true then string is "Palindrome", else string is "NOT Palindrome!".
|
|
|
|
|
We don't write code for others; what we will do is help you fix problems in your code. You have everything you need in the text to help you write the code. Good luck.
|
|
|
|
|
Write class Stack using array with the following attributes and methods:
class Stack
{
char items[100];
int top;
Stack()
{
top = -1;
}
}
See how it is not that difficult if you do it one piece at a time? Now you can fill in all the remaining parts.
|
|
|
|