Authentication window IIS ASP.net

2

Good I would like you to help me I was developing a window authentication with the asp.net language, the question is if it works and when I enter the page I get the name of the user that is logged in.

The problem is that when I upload my page to an IIS, the name of the logged-in user does not appear, but rather of the IIS, I would like you to help me.

Since when I run from my source code it works for me but when I upload it to IIS I do not get the user name of logeado window I get it

DefaultAppPol

Someone who can help me please. I tried everything but I can not get out

Whether it is possible or not for them to help me.

Only the problem is when I go to the IIS

HTML LOGIN.

<%

string strHostName = System.Net.Dns.GetHostName();
string clientIPAddress = System.Net.Dns.GetHostAddresses(strHostName).GetValue(1).ToString();
//txtIp.Text = (clientIPAddress);
txtUsuario.Text = System.Environment.UserName; 

%>
<!DOCTYPE html>


<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
 <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0" />
    <title>.:: Sistema de Usuarios | FINANCIERA QAPAQ S.A. ::.</title>

    <link rel="stylesheet" type="text/css" href="css/bootstrap.min.css" />
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
      <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/meyer-reset/2.0/reset.min.css">
 <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/meyer-reset/2.0/reset.min.css">

      <link rel="stylesheet" href="css/style4.css">
<!-- Optional theme -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap-theme.min.css" integrity="sha384-rHyoN1iRsVXV4nD0JutlnGaslCJuC7uwjduW9SVrLvRYooPp2bWYgmgJQIXwl/Sp" crossorigin="anonymous">

<!-- Latest compiled and minified JavaScript -->

<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>

</head>
    <script type="text/javascript">
        var usuario = document.getElementById('<%=txtUsuario.ClientID%>');
        usuario.readOnly = true;
    </script>
<body>
    <center>
    <form id="form1" runat="server" method="post">
          <div class="group">
    <asp:TextBox ID="txtUsuario" runat="server" Width="250px"  MinLines="1" MaxLength="15" readonly  CssClass="form-control" class="highlight"  for="inputSuccess3"   ></asp:TextBox>
         <label></label>
  </div>

                    <asp:Button runat="server" ID="btnLogin" Width="250px"  Onclick="btnLogin_Click" CssClass="btn btn-danger"  Text="Iniciar Session" />


         </form>
 </center>
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
  <script type="text/javascript" src="js/bootstrap.min.js"></script>
<script type="text/javascript" src="css/bootstrap.css"></script>
<script type="text/javascript" src="js/bootstrap.min.js"></script>
<script src='http://code.jquery.com/jquery-2.1.4.min.js'></script>    
 <script src='https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js'></script>
<script type="text/javascript" src="js/bootstrap.min.js"></script>
<script src='http://code.jquery.com/jquery-2.1.4.min.js'></script>    
<script src='https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js'></script>
    <script src="js/index4.js"></script>
</body>
</html>

WEBCONFIG.

<configuration>
    <configSections>
        <sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
            <section name="DesbloqueoUsuario.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
        </sectionGroup>
    </configSections>
    <system.web>
      <compilation debug="true" targetFramework="4.5" />
      <httpRuntime targetFramework="4.5" />



    </system.web>




  <connectionStrings>

    <add name="con"  connectionString="server=10.0.101.85\instbdd01; database=Seguridad;  user id=SA; password=SA123456789*;"  providerName="System.Data.SqlClient"/>
    <add name="conn"  connectionString="server=10.0.101.85\instbdd01; database=BatCliente;  user id=SA; password=SA123456789*;"  providerName="System.Data.SqlClient"/>

  </connectionStrings>
    <applicationSettings>
        <DesbloqueoUsuario.Properties.Settings>
            <setting name="DesbloqueoUsuario_localhost_WebService" serializeAs="String">
                <value>http://localhost:56117/WebService.asmx</value>
            </setting>
            <setting name="DesbloqueoUsuario_localhost1_WebService2" serializeAs="String">
                <value>http://localhost:56116/WebService2.asmx</value>
            </setting>
            <setting name="DesbloqueoUsuario_localhost9_WebService3" serializeAs="String">
                <value>http://localhost:56117/WebService3.asmx</value>
            </setting>
        </DesbloqueoUsuario.Properties.Settings>
    </applicationSettings>
    <system.serviceModel>
        <bindings />
        <client />
    </system.serviceModel>
</configuration>

problem in IIS

WHEN I EXECUTE ON MY PC

    
asked by PieroDev 04.04.2017 в 15:23
source

3 answers

3

For the case that you are raising there are several things that can affect the operation. I'll list the things you should review:

Considerations within the application

Ensure that the web.config has the following configuration.

<system.web>
  <authentication mode="Windows"></authentication>
  ......
</system.web>

To obtain the name of the user on the page (within the Web project)

protected void Page_Load(object sender, EventArgs e)
{
    Response.Write(User.Identity.Name);
}

To obtain the user's name from another project (eg a data layer referenced by the Web project)

System.Threading.Thread.CurrentPrincipal.Identity.Name

If you are debugging the project with IIS Express

Ensure that the configuration of Windows authentication is correct (anonymous authentication has to be disabled, because otherwise this will be the default mode that the application will take and it will never authenticate with Windows)

If you are going to run the project in IIS Local

Ensure that the "Windows Authentication" feature is installed on the IIS server. This is done from the "Add and Remove Programs" option of the Operating System

Then verify that the Authentication mode is correctly configured in the "Web Application" where you are doing the publication (the anonymous authentication has to be disabled for the same reason explained above)

    
answered by 06.04.2017 / 15:13
source
0

In your conectionString add Integrated Security=True; to make it look like this:

<add name="con"  connectionString="server=10.0.101.85\instbdd01; database=Seguridad;  user id=SA; password=SA123456789*; Integrated Security=True;"  providerName="System.Data.SqlClient"/>
<add name="conn"  connectionString="server=10.0.101.85\instbdd01; database=BatCliente;  user id=SA; password=SA123456789*; Integrated Security=True;"  providerName="System.Data.SqlClient"/>

The official documentation says:

  

When value false is assigned, the user ID and password specified in the connection string are used. When true , the current Windows credentials are used to perform authentication.

Or where appropriate, use:

txtUsuario.Text = System.Security.Principal.WindowsIdentity.GetCurrent().Name;
    
answered by 04.04.2017 в 17:27
0

You can try using one side:

System.Web.HttpContext.Current.User.Identity

Also, you should bear in mind that you need to have the windows authentication activated in the corresponding application. Otherwise, the user of the apppool itself may take you.

    
answered by 06.04.2017 в 14:55