登录asp.net时出现网络接口错误 [英] Network interface error while login in asp.net

查看:107
本文介绍了登录asp.net时出现网络接口错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,

当我尝试通过输入登录ID和密码登录时,它正在检查IP地址,因为我想仅允许用户从所选IP ...我已经设置了我的IIS。 net trust level to Medium然后它给我以下错误: -



请求类型'System.Net.NetworkInformation.NetworkInformationPermission,System,Version的权限= 4.0.0.0,文化=中立,PublicKeyToken = b77a5c561934e089'失败。



当我将信任等级设置为完全正常工作时...根据要求,信任级别应该只有中等。任何人都可以帮助我..谢谢提前





Hello,
When i m trying to login by entering login Id and password and it is checking the ip Address because i want to allow user from selected IP only..And i have set my IIS .net trust level to Medium then its giving me following error:-

Request for the permission of type 'System.Net.NetworkInformation.NetworkInformationPermission, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.

and when i am setting trust level to full its working proper..but as per requirement the trust level should be Medium only..Can anyone please help me out..Thanks in advance


 protected void btnLogin_Click(object sender, EventArgs e)
{
            string LoginName = txtloginname.Text.Trim();
            string Password = txtpassword.Text.Trim();
            AdminLogin oLogin = new AdminLogin();
            oLogin.LoginName = LoginName;
            oLogin.Password = Password;
            oLogin.MachineIp = "";
            string sa;
            string strHostName = System.Net.Dns.GetHostName();
            sa = System.Net.Dns.GetHostAddresses(strHostName).GetValue(0).ToString();
           
            if (HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"] != null)
            {
                sa = HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"].ToString();
            }
            else if (HttpContext.Current.Request.UserHostAddress.Length != 0)
            {
                sa = HttpContext.Current.Request.UserHostAddress;
                sa = HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"];
            }
            string s = GetMAcAddress();
            
            oLogin.MachineIp = sa.ToString().Trim();

            DataSet ds = AdminLoginManager.CheckLoginInfo(oLogin, conn);

                    if (ds.Tables[0].Rows.Count > 0)
                    {
                        
                            SessionInfo.LoginId = ds.Tables[0].Rows[0]["Admin_Login_Id"].ToString().Trim();
                            SessionInfo.Login_UserName = ds.Tables[0].Rows[0]["Admin_Login_Name"].ToString().Trim();

                            SessionInfo.LoginName = ds.Tables[0].Rows[0]["FullName"].ToString().Trim();

                            SessionInfo.LoginType = ds.Tables[0].Rows[0]["UserType"].ToString().Trim();

                            if (ds.Tables[0].Rows[0]["PwdChange"].ToString() == "N")
                            {
                                Response.Redirect("/ChangePassword.aspx", false);
                            }
                            else
                            {
                                Response.Redirect("/Admin_Home.aspx", false);
                            }
                            Log logObj = new Log();
                            string servername = "CjOrder";
                            string username = txtloginname.Text.Trim();
                            string eventtype = logObj.adUserValid;
                            string eventdesc = "User Logged In Successfully";
                            LogManager.Insert_Log(conn, servername, username, eventtype, eventdesc, oLogin.MachineIp);
                       
                    }
                    
          }     

private string GetMAcAddress()
    {
        string macAddress = string.Empty;
        foreach (System.Net.NetworkInformation.NetworkInterface nic in System.Net.NetworkInformation.NetworkInterface.GetAllNetworkInterfaces())
        {
            if (nic.OperationalStatus == System.Net.NetworkInformation.OperationalStatus.Up)
            {
                macAddress += nic.GetPhysicalAddress().ToString();
                break;
            }
        }
        return macAddress;
}

推荐答案

1)您可以使用permcalc [ ^ ]。

2)我不是真的在所有权限要求的顶部,但你想做一些低级别的东西。我可以想象,你需要registryaccess权限来获取接口的mac地址。有中等信任,你不会有。

3)你可以保持中等信任级别,但定义自定义策略以访问你的应用程序真正需要的内容:https://msdn.microsoft.com/en-us/library/ff648344.aspx [ ^ ]

4)你做了什么?本地机器的MAC地址全部连接在一起?第一种:使用stringbuilder进行连接,使用:在物理服务器上可能有10个以上的活动接口MAC。

5)IIS内置了IP访问安全性:https://www.iis.net/configreference/system.webserver/security/ipsecurity [ ^ ]



请澄清你的具体意图......
1) You can determine the exact permission requirement with permcalc[^].
2) I am not really on top with all permission requirements, but you want to do some low level stuff. I can imagine, that you need registryaccess permission to get mac address of the interface. With medium trust you won't have.
3) You can keep the medium trust level, but define custom policy to have access to what your application really needs: https://msdn.microsoft.com/en-us/library/ff648344.aspx[^]
4) What do you inted to do with local machine's MAC addresses all concatenated? First: use stringbuilder to concatenate, secound: you might have more than ten active interface MACs on a physical server.
5) IIS has built in IP access security: https://www.iis.net/configreference/system.webserver/security/ipsecurity[^]

Please clarify what your concrete intentions are...


这篇关于登录asp.net时出现网络接口错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆