=> dimasite

IT for(;;) fun!

  • Advertisements

Archive for the ‘ASP .NET’ Category

How to open Web.config?

Posted by Dmitrij Ivanov on October 16, 2010

1. Open machine.config on the local machine.

2. Open root web.config on the local machine.

3. Open web.config for the application at the root of the default web site.

4. Open web.config for a subdirectory of the application found at /MyApp.

5. Open web.config for an application at the root of another site.
WebConfigurationManager.OpenWebConfiguration("/", "Another Site");

6. Open the <location> tag for a subdirectory at the application level.
WebConfigurationManager.OpenWebConfiguration("/", null, "/subdir");

7. Open machine.config on another computer, using credentials provided.
WebConfigurationManager.OpenMachineConfiguration(null, "remotemachine", "user", "password");

take a look to the link


Posted in ASP .NET | Tagged: , , , , | Leave a Comment »

How to get current windows user name using ASP .NET

Posted by Dmitrij Ivanov on September 21, 2010

There are three different ways to obtain the same information.
protected void Page_Load(object sender, EventArgs e)
  System.Security.Principal.WindowsPrincipal windowsPrincipal = System.Threading.Thread.CurrentPrincipal as System.Security.Principal.WindowsPrincipal;
  string identityName1way = windowsPrincipal.Identity.Name;
  string identityName2way = HttpContext.Current.User.Identity.Name;
  string identityName3way = Request.ServerVariables["AUTH_USER"];
  Label1.Text = identityName1way + " or " + identityName2way + " or " + identityName3way;

The Web.config file should have authentication mode set to Windows.
     <authentication mode="Windows" />

Posted in ASP .NET | Tagged: , | Leave a Comment »