Solved

IIS 7 error when browsing asp.net website

Posted on 2013-01-12
7
889 Views
Last Modified: 2013-01-14
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
0
Comment
Question by:ocdc
  • 3
  • 3
7 Comments
 
LVL 13

Expert Comment

by:Surone1
ID: 38770760
you need to check if Len(NTuser) is at least 9 (or mylen is at least 1) before you use the mid function
0
 

Author Comment

by:ocdc
ID: 38771112
How do i do that? Thanks.
0
 
LVL 79

Accepted Solution

by:
David Johnson, CD, MVP earned 50 total points
ID: 38771123
You must not have anonymous authentication turned on. http://support.microsoft.com/kb/306359

You should do some error checking to ensure that you are actually getting a value for NTUser.
0
What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

 

Author Comment

by:ocdc
ID: 38771205
It is not turned on.
0
 
LVL 79

Expert Comment

by:David Johnson, CD, MVP
ID: 38771219
Do you have forms or Windows Authentication Turned On? (you need one or the other preferably Windows Authentication)
0
 

Author Comment

by:ocdc
ID: 38771297
Windows Authentication Turned On
0
 
LVL 79

Expert Comment

by:David Johnson, CD, MVP
ID: 38771339
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

0

Featured Post

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Here are the symptoms: You start receiving calls from users that one of your legacy web apps isn't coming up, so you log into your IIS 5 server to check it out.  When you pull up the services, you notice that the WWW Publishing service isn't runn…
Preparing an email is something we should all take special care with – especially when the email is for somebody you may not know very well. The pressures of everyday working life stacked with a hectic office environment can make this a real challen…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

832 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question