开发者

Publishing my asp.net web application gives 'Object reference not set to an instance of an object.'

开发者 https://www.devze.com 2023-03-17 01:44 出处:网络
My web app compiles and runs fine on my machine.However when I publish it to my IIS6 server, I get the infamous Object reference not set to an instance of an object. With the following stack trace

My web app compiles and runs fine on my machine. However when I publish it to my IIS6 server, I get the infamous Object reference not set to an instance of an object. With the following stack trace

[NullReferenceException: Object reference not set to an instance of an object.]
   ForYourInformation.LDAPDetails..ctor(IntPtr logonToken) in d:\documents\documents\visual studio 2010\Projects\ForYourInformation\ForYourInformation\Utils.cs:66
   ForYourInformation._Default.Page_Load(Object sender, EventArgs e) in d:\documents\documents\visual studio 2010\Projects\ForYourInformation\ForYourInformation\Default.aspx.cs:24
   System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +24
   System.Web.UI.Control.LoadRecursive() +70
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +3047

The flagged file Utils.cs is as follows

_UserName = windowsId.Name.Substring(windowsId.Name.IndexOf('\\') + 1);
        _DomainName = windowsId.Name.ToString().Remove(windowsId.Name.IndexOf('\\'));

        //Get users information from active directory
        DirectorySearcher search = new Directo开发者_如何学编程rySearcher("LDAP://DCHS");
        search.Filter = String.Format("(SAMAccountName={0})", _UserName);
        SearchResult result = search.FindOne();
        DirectoryEntry entry = result.GetDirectoryEntry();

        _FullName = result.Properties["givenName"][0].ToString() + ' ' + result.Properties["sn"][0].ToString();
        _Email = result.Properties["mail"][0].ToString();
        _FirstName = result.Properties["givenName"][0].ToString();
        _SSID = windowsId.User.ToString();

It goes and grabs the users active directory and security info. Line 66 is the DirectoryEntry line. I've got no idea whats going on here, since it works fine running locally.

Any help is appreciated thanks.


Here you go Matt, the result is return null. Check it out before you using it.

    SearchResult result = search.FindOne();
    if(result != null)
    {
       DirectoryEntry entry = result.GetDirectoryEntry();

How to tell from the report. In this line it tell you that the 66 line throw the first error, and its a null pointer. So in this line the only null can be the result, and here we go, you find it.

ForYourInformation.LDAPDetails..ctor(IntPtr logonToken) in d:\documents\documents\visual studio 2010\Projects\ForYourInformation\ForYourInformation\Utils.cs:66

0

精彩评论

暂无评论...
验证码 换一张
取 消