|
Hi,
I have a question about impersonation. I'm writing C# in asp.net for a web app. to be deployed on a Windows 2000 Server. I'm writing code to access a file that's located on a network folder. So inside my code, I need to perform "Impersonation" in order to have the client browser access the file. So looking at msdn, they give me the code for Impersonation by means of
LogonUser - > Duplicate Token -> Impersonate
But the problem is that there is a warning in the code snippet comments about executing the code in the windows 2000 environment. It says the code can only be run in Windows XP as there is a security risk if executed in Windows 2000.
MSDN Code Snippet:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfSystemSecurityPrincipalWindowsIdentityClassImpersonateTopic.asp
Can someone please tell me how i can access this file located on the network in Windows 2000 (if i shouldn't be using impersonation)?
Thanks!
Sharon
|
|
|
|
|
First of all, this question should be posted in the ASP.NET forum, but I'll answer anyway.
Instead of manually impersonating a user by handling the authentication yourself, ASP.NET already has this functionality built-in. By simply adding <identity impersonate="true" /> under the <system.web> configuration section in your Web.config file, you're half-way there. If this is for an intranet, IE will automatically use their domain credentials. You can force NTLM authentication (all handled for you by ASP.NET) by adding <authentication mode="Windows" /> under the same section I mentioned above. Done. Now IE will securely prompt for credentials if the user was not authenticated and will authenticate against the domain.
With your approach, you'd have to prompt for credentials in a web page. If you don't use an SSL certificate to encrypt the transfer, you've made a gaping hole in security because a simple packet sniffer could sniff domain usernames and passwords.
If you want to know how to impersonateusers anyway, lookup WindowsIdentity.Impersonate in the .NET Framework SDK. It provides a thorough example.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Hi, how can I set the cultureinfo to use in the propertygrid?
How can I select which properties of an object to show in the propertygrid? is posible?
Thank you!
La realidad no es más que impulsos eléctricos del cerebro - Morpheus
|
|
|
|
|
This is where the .NET ComponentModel comes into play. Read Enhancing Design-Time Support[^] in the .NET Framework SDK for starters, as well as the System.ComponentModel namespace classes.
Filtering the properties (or even "creating" properties) can be done in many ways, such as implementing a designer, a TypeConverter , or implementing the ICustomTypeDescriptor on your object.
As far as the CultureInfo goes, you need to set Thread.CurrentUICulture to the CultureInfo you want on the thread that owns the PropertyGrid instance (the thread that created it).
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
There are few examples in Code project dealing this. You can please refer these.
|
|
|
|
|
I was playing with the managed WebBrowser control wrapper included in .NET 2. One seemingly huge bit of missing functionality is when the NewWindow event is launched, I want to open the new window in my code using my control, not using the default browser! What's the deal here, did they forget?
I can use the messy COM interfaces to do this I know, but wow, did they actually forget this functionality or am I missing something?
#include "witty_sig.h"
|
|
|
|
|
They've left quite a bit of stuff out - just like every other class in the BCL. The major functionality is supported, though. You wouldn't want a bloated BCL now, would you?
I would recommend posting this feature request before it's too late by using the new MSDN developer center for VS 2005 and .NET 2.0. Browse to http://lab.msdn.microsoft.com/vs2005/Default.aspx[^]. You'll need a Passport, but you can post bugs and feature requests. This is primarily for VS 2005, but I've seen several .NET 2.0 bugs/requests slip in. You could always use the MSDN newsgroups, too.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
*prust*
Is it possible to implement a own shell-view for the Windows Explorer??
I don't want to create my own Explorer, but I need a special view to present the content of a folder to the user. Its possible to add a column to the details view of the Explorer window, but I need more.
I wrote a programm that analyses methods out of Java-Source files (*.java). Each found method in a file should get its own entry in a listview. Therefore I can not use the details view of the explorer. I need my own view.
I don't know if that is possible. But if its possible, how should I implement this "owner-drawn" view????
Shir Khan, the tiger
GVT
|
|
|
|
|
MSDN Magazine had an article[^] in the January 2004 edition about writing shell extensions in .NET. I'm not sure that it is 100% applicable, but perhaps it can provide a starting point.
Hope that helps a bit.
--Jesse
|
|
|
|
|
Shir Khan wrote:
Its possible to add a column to the details view of the Explorer window, but I need more.
That is correct, you can do this through a shell extension (Mike Dunn has written a nice article here[^]). However since you need more I would suggest you read Dino Esposito article on MSDN titled: More Windows 2000 UI Goodies: Extending Explorer Views by Customizing Hypertext Template Files[^]. I would caution you that soemthing like this would probably best be written in an unmanaged language, otherwise you are looking at a lot of additional work. Good luck.
- Nick Parker My Blog | My Articles
|
|
|
|
|
I am writing a DataBase layer DLL and I am having toruble reading the Config file to get the ConnectionString etc. To enable me to read the Config file with:
_connectionString = ConfigurationSettings.AppSettings[ "ConectionString" ];
from within my DataBase layer DLL what do I need to call the Config file and where do I put it so that it will read from this Config file both while debugging and when running the .exe which will create an object of the DataBase layer.
My Config file is as follows:
<?xml version="1.0" encoding="utf-8" ?><br />
<configuration><br />
<appSettings><br />
<add key="ConectionString" value="testing"/><br />
</appSettings><br />
</configuration>
|
|
|
|
|
The default executable loader does not load .config files into the AppDomain for DLLs - only EXEs. You either need to create your own loader or shim, or document that the host application must define an appSetting named "ConnectionString" in its .config file (which is a common approach, or error out).
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Hi all. I am working on a project where we have an embedded IE control on a Windows form, and one of the features we have been requested to produce is a " find on this page", where the user can type in a term, and if it exists, the browser control will scroll to it (similar to the existing functionality of IE's Edit->Find( on this page), without the dialog). the problem I am getting is that I see no elegant way of doing this, without parsing the HTML returned in the browser control, or wrapping a Javascript in some form of COM interop. Seems that there should be some method exposed in the Windows Browser control (mshtml.dll) for doing this, but I can't find it. All we need is for the method to take a string, and look for it on the displayed page. If it finds it, show it, otherwise, pop up a message box.
Any help in this matter will be greatly appreciated.
|
|
|
|
|
If you haven't already, you'll need to interop MSHTML. If you've installed VS.NET, Microsoft.mshtml.dll should already be in the GAC. You just need to add a reference (this contains all the automation interfaces for the DOM).
Get the IHTMLDocument2 reference by casting WebBrowser.Document to the interface. Then get the body property (an IHTMLElement ). Cast this to an IHTMLBodyElement and call createTextRange . This gives you an IHTMLTxtRange . You're almost done.
Call findText on the IHTMLTxtRange . Documentation for this method can be found in the Web Develoment -> Programming and Reusing the Browser section in MSDN Library[^]. If the text is found (it returns a bool ), the IHTMLTxtRange is modified to beginand end with the text that was found. Then simply call scrollIntoView on the IHTMLTxtRange , passing either true or false to position the text at the top or bottom of the window, respectively.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Thanks so much, this works great. I have one other quick question, how can I cycle down the document if more then one instance of the string is found? Say if they hit the button agai, it goes to the next instance, until findText returns false?
|
|
|
|
|
I again encourage you to read the MSHTML Reference[^] documentation I mentioned earlier if you haven't already.
The easiest way would be to call IHTMLTxtRange.moveStart to move to the end of the range, then call IHTMLTxtRange.moveEnd to move to the end of the body (there's many ways to do this). Then call findText again and repeat the process.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Hi!
I'm looking for any information on how to limit the internet bandwidth used by my program. I have found that this can be done by delaying ACK packet, but how can I do it from .NET framework (I dont want to use any unsafe code)
Thanks in advance
Piotrek
|
|
|
|
|
The .NET Framework languages we're not designed for such low level work. You would have to P/Invoke many API's and declare bunches of constants and structs to do it. There is no support in the .NET Framework for doing what your talking about. Everything about this project would be unsafe code...
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Thanks
Is it possible to limit (control) bandwidth in this way:
1. set socket buffer through the SetSocketOption and SocketOptionName.ReceiveBuffer to small value
2. do not take data from function call by the BeginReceive and/or do not call BegineReceive again
This should (I think) make full all buffers and the system should send same delaing packets waiting for me to make empty the buffers.
If it isnt possible could You point out some articles/codes about bandwidth limiting, please?
Thanks in advance
Piotrek
|
|
|
|
|
Those articles are few and far between. I actually haven't been able to find any that deal with an entire NIC, just a single application.
You idea works, if your application is the one you want to limit the bandwidth on, but it will NOT work for just the Internet and will NOT work for all bandwidth on a NIC. You can't modify the buffer sizes of the TCP/IP stack globally using your method, not can you modify the buffer sizes of other applications.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
I'm sorry that I didn't mention it before, but I want to limit only my application.
Thanks for help.
|
|
|
|
|
In, Aspx page, I would like to add programmatically a new element(c# or VB.NET) in the header of my aspx page.
Add element=toto,atribut=coucou value =”Y”
Example
<title>Default
<toto coucou="”Y”">
Thank you a lot
bye
-=zoltx=-
|
|
|
|
|
That makes no sense. Can you try explaining again what you want to do.
Also, this should really go in the ASP.NET[^] forum
"If a man empties his purse into his head, no man can take it away from him, for an investment in knowledge pays the best interest." -- Joseph E. O'Donnell
The Second EuroCPian Event will be in Brussels on the 4th of September
Can't manage to P/Invoke that Win32 API in .NET? Why not do interop the wiki way!
|
|
|
|
|
I would like to add a tag in the header in my aspx page
as <base href="http/....." />
for example
.....generate by VS
<base href="http://localhost/test1" />
......
Thank you
-=zoltx=-
|
|
|
|
|
I have an app that draws graphs. I want a tooltip that says the x and y value for the axis the mousepointer is over. That is not the main problem. The real problem is that the panel redpaints itself when the tooltip moves. (It now just shows the X and Y coordinate of the pointer) The tooltip moves on panel_Navigate which makes it repaint at every little mouse movement. I have read a little about Double buffering. Is there an easy way of implementing this? This did not work:
this.SetStyle(ControlStyles.UserPaint, true);
this.SetStyle(ControlStyles.AllPaintingInWmPaint, true);
this.SetStyle(ControlStyles.DoubleBuffer, true);
I have a form with a usercontrol with the panel to draw graphs inside it. I tried to make my own little derived panelclass which overrides the OnPaint method, but I just could not make it work properly because I have to draw the graphics inside the override method. That makes things a little tricky.
Any suggestions? Maybe I'm doing something wrong with the code above? I tried putting it inside all of the constructors, but nothing happend.
- Atle
|
|
|
|