ocdc
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.ServerVariab les("LOGON _USER"))
Line 63: mylen = Len(NTuser) -8
Line 64: NTuser = Mid(NTuser, 9, myLen)
Source File: C:\inetpub\wwwroot2\TEST\d efault.asp x Line: 64
Stack Trace:
[ArgumentException: Argument 'Length' must be greater or equal to zero.]
Microsoft.VisualBasic.Stri ngs.Mid(St ring str, Int32 Start, Int32 Length) +723658
ASP.default_aspx.page_Load (Object Sender, EventArgs E) in C:\inetpub\wwwroot2\TEST\d efault.asp x:64
System.Web.Util.CalliHelpe r.EventArg FunctionCa ller(IntPt r fp, Object o, Object t, EventArgs e) +25
System.Web.Util.CalliEvent HandlerDel egateProxy .Callback( Object sender, EventArgs e) +42
System.Web.UI.Control.OnLo ad(EventAr gs e) +132
System.Web.UI.Control.Load Recursive( ) +66
System.Web.UI.Page.Process RequestMai n(Boolean includeStagesBeforeAsyncPo int, Boolean includeStagesAfterAsyncPoi nt) +2428
Version Information: Microsoft .NET Framework Version:2.0.50727.4223; ASP.NET Version:2.0.50727.4223
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.ServerVariab
Line 63: mylen = Len(NTuser) -8
Line 64: NTuser = Mid(NTuser, 9, myLen)
Source File: C:\inetpub\wwwroot2\TEST\d
Stack Trace:
[ArgumentException: Argument 'Length' must be greater or equal to zero.]
Microsoft.VisualBasic.Stri
ASP.default_aspx.page_Load
System.Web.Util.CalliHelpe
System.Web.Util.CalliEvent
System.Web.UI.Control.OnLo
System.Web.UI.Control.Load
System.Web.UI.Page.Process
Version Information: Microsoft .NET Framework Version:2.0.50727.4223; ASP.NET Version:2.0.50727.4223
you need to check if Len(NTuser) is at least 9 (or mylen is at least 1) before you use the mid function
ASKER
How do i do that? Thanks.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
It is not turned on.
Do you have forms or Windows Authentication Turned On? (you need one or the other preferably Windows Authentication)
ASKER
Windows Authentication Turned On
Try this and check your results, expecially username length
Default.aspx
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>
Code behind default.aspx.vbPartial 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