locked
Error in Default.aspx - object reference not set to an instance of an object RRS feed

  • Question

  • User-283860200 posted

    Hello,

    I have a site in IIS 10 who's default document is configured to be default.aspx.

    When I goto site/ (or http://site) in browser, I get object reference not set to an instance of an object and can see the line of code.
    If instead I goto site/default.aspx (or http://site/default.aspx), it runs fine without error.

    I can't seem to find a reason for the differrence in behaviour (the fact that an unhandled exception is thrown) nor a reason for the error as the code is good and runs
    fine in Visual Studio debug mode.

    the code is a simple if/then:  If UserName.ToUpper <> "WHATEVER" then
    runs fine in VS, runs fine as http://site/default.aspx but errors when calling http://site and default.aspx is the default document in IIS 10.

    Can you suggest something i can check on?

    Thanks!

    Friday, December 14, 2018 7:06 PM

All replies

  • User-1174608757 posted

    Hi CSpace
    According to your description,I suggest you to check the default document in your WebSite in IIS manager.If the default Document is not default.aspx, that may leads to the error.
    Else, if not the error in default Document, could you please post the detail about the UserName? I am looking forward to  your reply.

    Best Regards 

    Wei Zhang

    Monday, December 17, 2018 8:37 AM
  • User-283860200 posted

    Hi and thanks for your reply.

    The default document in IIS is default.aspx.

    Code is:

    UserName = Request.ServerVariables("LOGON_USER")
    UserName = Replace(UserName, "MYDOMAIN\", "", 1, Len(UserName), CompareMethod.Text)
    If UserName.ToUpper <> "WHATEVER" then  '<<<ERROR IS ON THIS LINE <<<<
        ...some code here....
    End If

    The strange thing about this is when the URL contains the page name (http://site/default.aspx) it runs fine, without it (http://site), the error is thrown.
    Also runs fine in VS.

    Monday, December 17, 2018 1:47 PM
  • User-1174608757 posted

    Hi CSpace,

    According to the code you posted, I have made a sample  on my side. However it still works well.

    Try to remote debug on a remoteIIS Computer.Here is the link,I hope it can help you.

    https://docs.microsoft.com/en-us/visualstudio/debugger/remote-debugging-aspnet-on-a-remote-iis-7-5-computer?view=vs-2017

    Best Regards

    Wei Zhang 

    Thursday, December 20, 2018 8:05 AM