|
This is ambiguous. Local to who? The client or the server?
--Colin Mackay--
"In the confrontation between the stream and the rock, the stream always wins - not through strength but perseverance." (H. Jackson Brown)
|
|
|
|
|
Local is the client machine
|
|
|
|
|
Hello all,
I posted this to microsoft.public.dotnet.framework.remoting
but it's awfully quiet over there. Hopefully someone here can shed
some light on this.
A client makes a call on a ContextBoundObject. The call is a simple call
to a property accessor. Depending upon the current values of a Singleton
I either want to simply return the value of the property of the object
or,
--> leaving the actual value of the field unchanged <--
return a different value.
A simple example would be
1) a client references a property of an object,
2) a security setting is checked and
3) either the actual value is returned - or - something like "Access
Denied" is put in it's place.
When RealProxy sends back the IMethodReturnMessage, the ReturnValue
property is read only. How can I alter this value before passing it back
to the client? Most of the AOP examples I have run across have not dealt
with this.
Thanks
Robert Zurer
robert@zurer.com
|
|
|
|
|
You'll have to extend RealProxy with your own class and override Invoke . Implement IMethodReturnMessage and then you can access the IDictionary through the IMessage.Properties (since IMethodReturnMessage implements IMessage ). To make sure that the ContextBoundObject uses your RealProxy instead, derive from ProxyAttribute to return an instance of your custom RealProxy and attribute your ContextBoundObject with your derived ProxyAttribute (see the SDK documentation for ProxyAttribute for an example).
If you also see the SDK documentation for the RealProxy.Invoke abstract method, you'll see an example of how this can be done as well.
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
This was extremely helpful. You really pointed me in the right direction.
Thanks so much.
Robert Zurer
robert@zurer.com
|
|
|
|
|
Glad I could help! Out of curiosity, though, why not just throw an UnauthorizedAccessException or something from your ContextBoundObject , and handle that in your client app?
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
One reason is the the security is very granular. For instance, if the client wants to see Employee.Name, Employee.Position and Employee.Salary but has no rights to Employee.Salary, I want to return
Name: Ludwig Wittgenstein
Position: TA, Philosophy
SSN : Access Denied
rather than throwing an execption.
I could easily pass around some sort of security token and handle this in the get_Methods, but my aim is to have my business objects contain ONLY business logic. I want security, profiling, versioning and concurrency concerns to be coded using aspect-oriented techniques.
Robert Zurer
robert@zurer.com
|
|
|
|
|
I guess I'm of the mind that while modularity is good (I'm a stickler for a good object-model), allowing some degree of control / not hiding too much is good between objects. For example, our data tier objects in the app I designed always throw exceptions unless they can recover from certain exceptions, while the business objects or UI tier decide what to do with the exceptions. This allows the app to pass extra information to the client about why the exception occured (not to mention it's handy to debug when some of my guys don't have the source for some components) and allows the caller to decide how to handle it. We also use proxies ala remoting. I guess whatever works for you, though. There's never an absolute correct way in development! (Although there are a lot of stupid and flat-out wrong ones...not that yours is - just my commentary! )
I'm going to have to read-up on this aspect-oriented technique. I've heard it mentioned several times and know there's an article around here in CP somewhere, I've just never read it. I'll have to do that and google for a few other resources, but if you've got a link or too to something you found useful, I'd sure appreciate it.
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
There is a tremendous amount out there. I really should have kept a list but here are two.
http://msdn.microsoft.com/msdnmag/issues/02/03/AOP/default.aspx
http://msdn.microsoft.com/msdnmag/issues/03/03/contextsinnet/
Robert
|
|
|
|
|
Interesting - since the public inception of .NET (and even for a while before that with some of my newer COM libraries) I've already been programming like most of what I read. I guess it just made sense too - to basically delegate responsibility to unknown objects at compile time and piece together those components at runtime. The application I architected for work works very much like that, although it could use a complete overhaul (the CEO gave me a couple weeks to design an app that has about 400,000 lines of actual code, is Internet-deployed, and now includes far too many "modules" to be deployed in such a way - plus it had to be easy enough for entry-level programmers / industrial engineers - who are now much better through lots of tutalige - to work on).
I've spent a lot of time in previous years studying COM (started about the time it evolved from OLE to COM) and especially all the interfaces that Office commonly implements. With a sprinkle of that with some of the stuff I developed since I originally architect the app (that is, I knew from the start this would come back to bite us so I kept track of everything I wanted to do in the first place but couldn't because we either didn't have time for a good design or didn't have the technical help from the rest of the code monkeys that was necessary). The Microsoft Patterns and Practices added a few more good ideas to the batch.
Thanks for the resources, though! At least I got a better grip on it and - strangly enough - realize that I've been doing it for a while so I don't feel like I'm missing the train!
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
Here's a MS WebTV piece detailing your original post.
http://www.microsoft.com/downloads/details.aspx?FamilyId=EF89345E-01A6-4AB1-8DDF-565286CC5DAC&displaylang=en
The presenter mentions that this is a more lightweight solution than using the MessageSink chain, implying that it could work the MessageSink chain.
In fact it can, using the ReturnValue property of MethodReturnMessageWrapper which can be assigned.
IMessage retMsg = nextSink.SyncProcessMessage(msg);
MethodReturnMessageWrapper mrm = new MethodReturnMessageWrapper((IMethodReturnMessage)retMsg);
Console.WriteLine("Here is the intercepted ReturnValue {0}", mrm.ReturnValue);
Robert Zurer
robert@zurer.com
Robert Zurer
robert@zurer.com
|
|
|
|
|
I need to get the following code working in C#:
char szText[255];
::SendMessage(hwndCurr, WM_GETTEXT, 255, (LPARAM)szText);
m_strPassword = szText;
And I've defined the SendMessage function
const int WM_GETTEXT = 0x000D;
[DllImport("user32.dll")]
static extern int SendMessage(IntPtr window, int message, int wparam, [Out]long lparam);
Does anybody know what I should do to make this work?
Andreas Philipson
|
|
|
|
|
Define it like so:
const int WM_GETTEXT = 0x000D;
[DllImport("user32.dll", CharSet=CharSet.Ansi)]
static extern int SendMessage(IntPtr hWnd, int msg, int wParam, out char[] lParam); You can get the HWND from controls' Handle property (and remember that Form derives from Control , so it has a handle too). Notice that I also used the out keyword (not the OutAttribute , which you could still use). This is necessary to get this to work in .NET. Call it like so:
char[] text = new char[255];
SendMessage(myTextBox.Handle, WM_GETTEXT, 255, out text);
password = text; Now, if you're some cracker trying to get a password from another application, keep in mind that calls to WM_GETTEXT from another process for Edit controls (TextBox controls in .NET) with the ES_PASSWORD style set return an empty string (or NULL - I don't remember)...and get a life!
If you're not a cracker, ignore the above statement except the bit about password fields in other processes!
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
Thanks for the help! I'll try it when I get home.
And regarding my use of this code - I'm trying to create a Password Manager which allows Drag&Drop to any edit control.
Andreas Philipson
|
|
|
|
|
After changing the solution to
[DllImport("user32.dll", CharSet=CharSet.Ansi)]
static extern int SendMessage(IntPtr hWnd, int msg, int wParam, [Out]StringBuilder lParam);
It works perfectly! Thanks again!
Andreas Philipson
|
|
|
|
|
Thank you Heath Stewart:
I saw all of the source-code.But they are local-hooks
I really want to know journal-hooks .
thamk you.
sdfasd
|
|
|
|
|
I have a problem with axWebBrowser/Word, then opening a document in axWebBrowser.
I want to open the document without commandbars and ruler, but word get the settings from a template file (Normal.dot) witch has the settings from the last used word document stored.
I do not want to delete the users registry settings or template file might not be so popular, even if it's recreated the next time word ends.
Please, how can i by code (C#) turn the commandbars and rulers off in both office 2000 and XP.....
any help is appriciated: martin.jonsson@ifsab.se
Martin Jonsson
|
|
|
|
|
Both the WebBrowser control (and MSHTML that it hosts) and Word implement the IOleCommandTarget . This interface (or rather, its implementation) allows for command execution using simple strings (when used in automation) or command IDs. The WebBrowser control also has a custom set of command IDs, as well as MSHTML.
One of the standard command IDs, OLECMDID_HIDETOOLBARS , should be supported by Word. I'm not sure if IOleCommandTarget implementations MUST support the standards, but rest assured Office most likely does because the standard OLEDMCID enumerations were first defined by Office 95 (good indication that Office supports them still).
Now, because the WebBrowser control is an ActiveX container, getting its IOleCommandTarget interface (in .NET, querying for an interface is as simple as casting your object to said interface) and sending that command may just be enough. You'll either have to create an interop assumly with IOleCommandTarget and the various enumerations it uses, or create it yourself.
You can also send the command IDs (perhaps identified by their numbers, like OLECMDID_HIDETOOLBARS is defined as 24) through IWebBrowser2.ExecWB (IWebBrowser2 is the class interface for the WebBrowser control). I don't know if this will automatically be sent to the automation server (in this case, Word.Application) but - depending on how everything is sited - it's pretty likely and definitely worth a try. If not, you'll have to request the child object from the WebBrowser's site to get the Word doc in order to get the Word.Application, and cast to IOleCommandTarget to execute the command on it.
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
Hi I am karthik, I need to create application, which creates thread dynamically and I need to pass unique Data/message to the thread (dynamically created thread).
How to pass Data/message from the application to the thread? It varies from thread to thread.
|
|
|
|
|
You cannot pass parematers to a method on a new thread. The method signature must be as follows:
void DoStuff(){
}
Instead of passing parameters use static variables. Note: Access to a static variable from multiple threads must be synchronized ..
|
|
|
|
|
A better way than using Thread as the above Anonymous person said, is to use worker threads in a thread pool, which can take a state object (which could be a single object, and array, collection, list, whatever). See ThreadPool.QueueUserWorkItem . There are many other useful methods that are helpful when synchronizing threads in the ThreadPool class you should check out. The ThreadPool , btw, is to make sure your application doesn't spawn threads uncontrollably. Many times, this is very important unless you're dealing with real-time apps (and most you write in your life won't be) otherwise you could monopolize the system's resources.
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
Hi,
I'm a beginner Windows programmer. I need to write a program that will copy files across networked servers, which may need to authenticate the user as he/she access the remote server. The user may type "\\remoteserver\d$\afile". If the user has accounts on both servers, it will just copy. If the currently logged in user does not have the same account on the remote server, the program is supposed to get the user id and password and pass it along to the remote server, just like the Windows Explorer.
I went round and round and trying with WNet APIs, System.Security.Permissions, System.Security.Principal. I did not get anywhere.
Any help will be greatly appreciated.
Thanks!!
|
|
|
|
|
Actually - in a domain setup - the user account doesn't exist on different computers (except, perhaps, different DCs that either cache or backup accounts). That's only a low-grade workgroup trick or for local users.
To accomplish what you want, you have to program the prompt yourself and deal with impersonation (which may cause problems on the local end if the impersonated user doesn't have access to the source resource). The fact is that .NET is a basic framework and doesn't include all functionality in Windows.
First, attempt a File.Copy . If you get an UnauthorizedAccessException , show a modal dialog to get the username and password (of course, mask the password using the TextBox.PasswordChar property). Then you're going to want to impersonate the requested user account. See the SDK documentation for WindowsIdentity.Impersonate for details and very good example source (P/Invoking native functions is required in .NET 1.x at least). Finally, perform the File.Copy again, and undo and close the impersonation handles (this is covered in the sample source I mentioned).
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
Heath, Thank you so much for your help. I will give it a try.
~Sherry
|
|
|
|
|
Im am trying to write an application that involves alot of TextBoxes that the user can input to. Is there a way to create an array of TextBoxes so I can just loop through them all?
Thanks
Matt
|
|
|
|