Solved

IIS 7 error when browsing asp.net website

Posted on 2013-01-12
7
876 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 78

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
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 

Author Comment

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

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 78

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

What is an ISAPI filter?   •      It's an assembly (.dll file) that can add or change the way IIS works.   •      They can be enabled globally for your web server or on a site-by-site basis.   When the IIS server receives a request, enabling the ISAPI fi…
When it comes to showing a 404 error page to your visitors, you do not want that generic page to show, and you especially do not want your hosting provider’s ad error page to show either. In this article, I will show you how to enable the custom 40…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

746 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now