Solved

IIS 7 error when browsing asp.net website

Posted on 2013-01-12
7
907 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 81

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
Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

 

Author Comment

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

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 81

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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Logparser is the smartest tool I have ever used in parsing IIS log files and there are many interesting things I wanted to share with everyone one of the  real-world  scenario from my current project. Let's get started with  scenario - How do w…
Prologue It is often required to host multiple websites on a single instance of IIS, mostly in development environments instead of on production servers. I am sure it is not much a preferred solution on production servers but this is at least a pos…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

687 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