Link to home
Start Free TrialLog in
Avatar of ocdc
ocdcFlag for United States of America

asked on

IIS 7 error when browsing asp.net website

when browsing ASP.net from IIS 7,  I am getting the following error. How can I change:

mylen = Len(NTuser) -8
NTuser = Mid(NTuser, 9, myLen)            

 so that it wont give me an error.


Argument 'Length' must be greater or equal to zero.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.ArgumentException: Argument 'Length' must be greater or equal to zero.

Source Error:
Line 62:         NTuser = UCase(Request.ServerVariables("LOGON_USER"))
Line 63:         mylen = Len(NTuser) -8
Line 64:         NTuser = Mid(NTuser, 9, myLen)

Source File: C:\inetpub\wwwroot2\TEST\default.aspx    Line: 64

Stack Trace:
[ArgumentException: Argument 'Length' must be greater or equal to zero.]
   Microsoft.VisualBasic.Strings.Mid(String str, Int32 Start, Int32 Length) +723658
   ASP.default_aspx.page_Load(Object Sender, EventArgs E) in C:\inetpub\wwwroot2\TEST\default.aspx:64
   System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +25
   System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +42
   System.Web.UI.Control.OnLoad(EventArgs e) +132
   System.Web.UI.Control.LoadRecursive() +66
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2428

Version Information: Microsoft .NET Framework Version:2.0.50727.4223; ASP.NET Version:2.0.50727.4223
Avatar of Surone1
Surone1
Flag of Suriname image

you need to check if Len(NTuser) is at least 9 (or mylen is at least 1) before you use the mid function
Avatar of ocdc

ASKER

How do i do that? Thanks.
ASKER CERTIFIED SOLUTION
Avatar of David Johnson, CD
David Johnson, CD
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of ocdc

ASKER

It is not turned on.
Do you have forms or Windows Authentication Turned On? (you need one or the other preferably Windows Authentication)
Avatar of ocdc

ASKER

Windows Authentication Turned On
Try this and check your results, expecially username length

Default.aspx
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Web Server Username Test</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    Username is: <asp:TextBox ID="TextBox1" runat="server" Width="386px">Username</asp:TextBox>
    Username Length is: <asp:Label ID="Label1" runat="server"></asp:Label>
    Uppercase Username is: <asp:Label ID="Label3" runat="server"></asp:Label>
    After Mid-String Operation: <asp:Label ID="Label4" runat="server"></asp:Label>
    </div>
    </form>
</body>
</html>

Open in new window

Code behind default.aspx.vb
Partial Class _Default
    Inherits System.Web.UI.Page
    Protected Sub TextBox1_Load(sender As Object, e As EventArgs) Handles TextBox1.Load
        TextBox1.Text = Request.ServerVariables("LOGON_USER")
        Label1.Text = Len(Request.ServerVariables("LOGON_USER"))
        Label3.Text = UCase(Request.ServerVariables("LOGON_USER"))
        Label4.Text = Mid(UCase(Request.ServerVariables("LOGON_USER")), 9, Len(Request.ServerVariables("LOGON_USER")))
    End Sub
End Class

Open in new window