How to differentiate between / (the root) and /default.aspx in ASP.NET - asp.net

Request.RawUrl always returns the /default.aspx variant. I did not find any way at all to differentiate between these urls. Does anybody know how to do that?
Environment is .NET 3.5SP1 on IIS 7.

I actually had to combat this same problem when designing my URL Rewriter. It has to do with the processes that occur before you can even access the URL's. To get around this you have to make sure that in IIS 7 the default page handling is turned off. Because if there is no default page handling it is not going to go through the extra step of trying to map it to the drive, so you will be the exact URL requested. But this may or may not be an option depending on if you are using System.Web.Routing or not.
To turn off the default page handling you need to do the following:
Go to your site in IIS
Go to Default Document
Click Disable in the top right corner.
Or you can add the following to your web.config:
<system.webServer>
<!-- ... other tags here ... -->
<defaultDocument enabled="false" />
</system.webServer>
After you do this the default document will be no longer added to your URL. However be warned that since this is no longer active you cannot rely on default.aspx actually mapping to your directories, you will have to handle this manually or use something like System.Web.Routing to handle this functionality.
To accomplish the same in IIS 6 you need to turn on wildcards:
The following instructions apply for IIS 6.
Open IIS and right-click on the website and select 'properties'.
Click the 'Configuration' button under Application Settings section
Click the 'Insert...' button to create a new wildcard mapping
Set the executable textbox to aspnet_isapi.dll file location.
for .net 2.0, 3.0, 3.5: C:\Windows\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll
Make sure the checkbox 'Verify that file exists' is not checked.
Press 'OK' to confirm and close all the windows.
NOTE: by the way all the source is available on the site I linked above incase you were curious how I was doing things.

Related

ConfigurationManager.AppSettings("IsDebugMode") is returning null

Background: I'm developing a website in ASP.NET with VB.NET backend, .net framework is 4.0. It's actually a redesign of an existing site, and everything works on the old version, and in fact the settings are the same there...
So I've got a master page for the admin section of my website which requires RSA authentication, however I want to skip that part of it obviously when I just hit f5 and run in debug on my local machine. So at the beginning of the page load event I do a check for...
If NOT ConfigurationManager.AppSettings("IsDebugMode") then
here's my code for authentication...
else
return true 'user automatically authenticated
end if
however, when I hit f5, it keeps throwing the error "Object reference not set to an instance of an object." I've googled it, and it looks like this syntax is correct, and like I said, the code is copy/pasted from the existing site, which functions the same in this area, and works just fine.
Is there a setting somewhere that I need to "turn on" this feature? I've never used the configuration manager before, so I'm not sure if it is requiring more than I've built so far. Anyone familiar with this?
Find and open web.config file, it's usually in the root directory of your web application, locate the appSettings section, add in an entry like:
<add key="IsDebugMode" value="true" />

The Web server is configured to not list the contents of this directory. asp.net vs 2012 error?

Got following Error:
HTTP Error 403.14 - Forbidden
The Web server is configured to not list the contents of this directory.
this is how I linked css file.
<link rel="stylesheet" type="text/css" href="~/styles/StyleSheet.css" />
i am using master page for first time. i did added master page in iss server.
i enabled the directory setting in my iss 8.0
Have you tried setting the following within your web.config file :
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>
The Web server is configured to not list the contents of this directory
The keyword in the error is list.
That sounds more like you do not have a default document set up. If you don't have one, nor don't request a specific document (e.g. http://www.foobar.com/ or http://www.foobar.com/foo.html respectively) IIS will not "know" what to "serve" to the browser nor will it, nor should you expect it to, list the contents of that directory (instead).
See: Microsoft Support: Error 403.14
A Short Story Of A Lost Controller, And A Happy Ending
Let's say you have a controller called Data, in the project file /Controllers/DataController.cs. You can access it just fine via http://yoursite.com/data, which is handled by the DataController.Index action method.
Then, somehow, it breaks, and you start getting "The Web server is configured to not list the contents of this directory" when you visit this URL. Strangely, visiting /data/index still works! You try all the suggestions found online to make this work but can't seem to do it. What could it be?
Perhaps you ought to think about what the error means. It says that when you visit /data, it finds a directory there, but you aren't allowed to see the files in it. Setting aside the fact that your routing doesn't seem to work and it should, could there actually be a directory there?
Yes, there could! In your web project, you cleverly added folder /Data! This is a physical folder that takes precedence in the server's static routing rules (since you didn't rewrite those so physical files would be looked at after managed virtual paths).
The solution is thus to rename the folder, or rename the controller, one or the other. This will fix your problem quite speedily and you may then proceed on your merry way coding long into the night to the enveloping strains of techno Spanish mandolin trance music, with your trusty cat snoozing on your foot and the cold beverage of your choice beading up on the desk next to you!
The Ramesh Rajendran's answer must working, but you can use look at what is the modules your web application use and add in system.webServer tag on webconfig file to they use it. I had this error also in a test web application when I put it on Server IIS.
It's very strange not list the contents with the option enabled on IIS Web Server.
When you press Ctrl+F5, then IIS don't understand what to serve as you don't have any Default aspx file in your site , i recommend you to add a aspx file by going to Add>NewItem>Webform>
Note: remember to check the box at bottom right , "select from master page"
after selecting , save all the pages and just open your default.aspx file and you will surely see the reflected design as you did in master page.
Master pages are not aspx file but serve as a template for other webpages , so you cant just open master page.
Don't start the debugger while you are on the master page. EdSF pretty much summed up why.
In addition, you also may need to set a default start page(right click, set as start page).
You should define a default document value in web config and disable directory browsing.
<system.webServer>
<defaultDocument>
<files>
<add value="insertion.aspx" />
</files>
</defaultDocument>
<directoryBrowse enabled="false" />

Detailed 500 error message, ASP + IIS 7.5

IIS 7.5 , 2008rc2, classic asp, 500 error msg:
The page cannot be displayed because an internal server error has occurred.
I need to know how to configure IIS to get a more detailed error.
I've tried setting to true all of debugging options in the ASP configuration.
But that didn't work. Can anyone help me?
I have come to the same problem and fixed the same way as Alex K.
So if "Send Errors To Browser" is not working set also this:
Error Pages -> 500 -> Edit Feature Settings -> "Detailed Errors"
Also note that if the content of the error page sent back is quite short and you're using IE, IE will happily ignore the useful content sent back by the server and show you its own generic error page instead. You can turn this off in IE's options, or use a different browser.
If you're on a remote server you can configure your web.config file like so:
<configuration>
<system.webServer>
<httpErrors errorMode="Detailed" />
<asp scriptErrorSentToBrowser="true"/>
</system.webServer>
<system.web>
<customErrors mode="Off"/>
<compilation debug="true"/>
</system.web>
Double click "ASP" in the site's Home screen in IIS admin, expand "Debugging Properties", enable "Send errors to browser", and click "Apply".
Under "Error Pages" on the home screen select "500", then "Edit feature settings" and select "Detailed Errors".
Note that the same steps apply for IIS 8.0 (Windows Server 2012).
After trying Vaclav's and Alex's answer, I still had to disable "Show friendly HTTP error messages" in IE
TLDR:First determine where in the pipeline you're getting the error from (scroll looking for screenshots of something that resembles your error), make changes to get something new, repeat.
First determine what error message you are actually seeing.
If you are seeing the file located here...
%SystemDrive%\inetpub\custerr<LANGUAGE-TAG>\500.htm
...which generally looks like this:
**...then you know you are seeing the currently configured error page in IIS ** and you do NOT need to change the ASP.net customErrors setting, asp error detail setting, or "show friendly http errors" browser setting.
You may want to look at the above referenced path instead of trusting my screenshot just in case somebody changed it.
"Yes, I see the above described error..."
In this case, you are seeing the setting of <httpErrors> or in IIS Manager it's Error Pages --> Edit Feature Settings. The default for this is errorMode=DetailedLocalOnly at the server node level (as opposed to the site level) which means that while you will see this configured error page while remote, you should be able to log on locally to the server and see the full error which should look something like this:
You should have everything that you need at that point to fix the current error.
"But I don't see the detailed error even browsing on the server"
That leaves a couple of possibilities.
The browser you are using on the server is configured to use a proxy
in its connection settings so it is not being seen as "local".
You're not actually browsing to the site you think you are browsing to - this commonly happens when there's a load balancer involved. Do a ping check to see if dns gives you an IP on the server or somewhere else.
Your site's httpErrors settings is set for "Custom" only. Change it to "DetailedLocalOnly". However, if you have a configuration error, this may not work since the site level httpErrors is also a configuration item. In that case proceed to #4
The default for httpErrors for all sites is set for "Custom". In this case you need to click on the top level server node in IIS Manager (and not a particular site) and change the httpErrors settings there to DetailedLocalOnly. If this is an internal server and you're not worried about divulging sensitive information, you could also set it to "Detailed" which will allow you to see the error from clients other than the server.
You're missing a module on the server like UrlRewrite (this one bites me a lot, and it often gives the generic message regardless of the httpErrors settings).
"Logging on to the server is not an option for me"
Change your site's httpErrors to "Detailed" so you can see it remotely. But if it doesn't work your error might already be a config error, see #3 immediately above. So you might be stuck with #4 or #5 and you're going to need somebody from your server team.
"I'm not seeing the error page described above. I'm seeing something different"
If you see this...
...and you expect to see something like this...
...then you need to change "Send errors to browser" to true in IIS Manager, under Site --> IIS --> ASP --> Debugging Properties
If you see this...
or this...
...you need to disable friendly errors in your browser or use fiddler's webview to look at the actual response vs what your browser chooses to show you.
If you see this...
...then custom errors is working but you don't have a custom error page (of course at this point were talking about .net and not classic asp). You need to change your customErrors tag in your web.config to RemoteOnly to view on the server, or Off to view remotely.
If you see something that is styled like your site, then custom errors is likely On or RemoteOnly and it's displaying the custom page (Views->Shared->Error.cshtml in MVC for example). That said, it is unlikely but possible that somebody changed the pages in IIS for httpErrors so see the first section on that.
In web.config under
<system.webServer>
replace (or add) the line
<httpErrors errorMode="Detailed"></httpErrors>
with
<httpErrors existingResponse="PassThrough" errorMode="Detailed"></httpErrors>
This is because by default IIS7 intercepts HTTP status codes such as 4xx and 5xx generated by applications further up the pipeline.
Next, enable "Send Errors to Browser" under the "ASP" section, and under "Error Pages / Edit Feature Settings", select "Detailed errors".
Also, give Write permissions on the website folder to the IIS_IUSRS builtin group.
try setting the value of the "existingResponse" httpErrors attribute to "PassThrough". Mine was set at "Replace" which was causing the YSOD not to display.
<httpErrors errorMode="Detailed" existingResponse="PassThrough">
One thing nobody's mentioned is as a very quick and temporary fix, you can view the error on the localhost of that web server.
You may also verify that if you changed your main website folder (c:\inetpub\wwwroot) to another folder you must give read permission to the IIS_IUSRS group in the new folder.
Fot people who have tried EVERYTHING and just CANNOT get the error details to show, like me, it's a good idea to check the different levels of configuration. I have a config file on Website level and on Application level (inside the website) check both. Also, as it turned out, I had Detailed Errors disabled on the highest node in IIS (just underneath Start Page, it has the name that is the same as the webservers computername). Check the Error Pages there.
Found it.
http://blogs.iis.net/ksingla/archive/2009/02/16/iis-7-5-updates-to-custom-errors-and-compression.aspx
run cmd as administrator, go to your system32\inetsrv folder and execute:
appcmd.exe set config -section:system.webServer/httpErrors -allowAbsolutePathsWhenDelegated:true
Now I can see detailed asp errors .
If you run the browser in the server and test your url of the project with the local ip you have received all errors of that project without a generally error page(for example 500 error page).
In my case it was permission issue.
Open application folder properties -> Security tab -> Edit -> Add
IIS AppPool\[DefaultAppPool or any other apppool] (if use ApplicationPoolIdentity option)
IUSRS
IIS_IUSRS
Double check the encoding of the asp file you are testing.
For instance if you created a file like below on a Windows Server Core 2019 :
echo "<%# LANGUAGE=Javascript %>" > test.asp
echo "<%Response.Write("test");%>" >> test.asp
Then test.asp will be encoded in Unicode, and requesting it will produce a 500 without any details.
Do a notepad test.asp, then click on "Save As..." and choose "ANSI" encoding to fix it.

Web.Routing for the site root or homepage

I am doing some work with Web.Routing, using it to have friendly urls and nice Rest like interfaces to a site that is essentially rendered by a single IHttpHandler. There are no webforms, the handler generates all the html/json and writes it as part of process request.
This works well for things like /Sites/Accounting for example, but I can't get it to work for the site root, i.e. '/'.
I have tried registering a route with an empty string, with 'default.aspx' (which is the empty aspx file I keep in my root folder to play nice with cassini and iis). I set RouteExistingFiles to false explicitly, but whatever I do when hitting the root url it still opens default.axpx, which has no code it inherits from, and contains a simple h1 tag to show that I've hit it.
I don't want to change the default file to redirect to a desired route, I just want the equivalent of a 'default' route that is applied when no other routes are found, similar to MVC.
For reference, the previous version of the site didn't use Web.Routing, but had a handler referenced in the web.config that was perfectly capable of intercepting requests for the root or default.aspx.
Specs: ASP.NET 3.5sp1, C#, no webforms, MVC or openrasta. Plain old IHttpHandlers.
Fixed my own problem: the issue is the integrated web server, Cassini or some such. Seems that it doesnt play nice with routing, and will by default simply return the default.aspx file or, if it is missing, show a directory listing.
Using IIS with a virtual directory works fine, but is annoying (frustrates code sharers because they need to set up new virtual directories when they open my app, and pollutes my own IIS instance. Bah. Probably what I'll do for the moment however, or setup a new application manually so I can use the domain host only path like what will exist in live.
An alternative is to use the updated version of cassini, seen here, which works if the default.aspx file is missing, but I have not worked out how to integrate it with visual studio yet. Any help would be appreciated, but its not a big priority given I have workarounds.
I realise that this is a really old post, but I just ran into the same problem using VS2012, so I'm posting this here just in case.
I solved the problem by installing IIS Express and setting the project to use IIS Express in Visual Studio. Solved the problem.

How do I configure IIS to handle really large file uploads?

Platform: IIS 6, ASP.Net 2.0 (.Net 3.5), Server 2003.
I'm building an application that accepts files from a user, processes them, and returns a result. The file is uploaded using HTTP POST to an ASP.Net web form. The application is expecting some large files (hundreds of MB).
I'm using SWFUpload to accomplish the upload with a nice progress bar, but that's not contributing to the issue, because when I bypass it using a standard HTML form pointing at my upload accepter page, I get the exact same error. When using the progress bar, the upload continues to 100%, then fails. With a standard form, the behavior appears to be the same.
I'm having a problem right now uploading a file that's about 150MB. I've changed every settings I can find, but still no luck.
Here's a summary of what I've changed so far:
In Web.config:
Added this inside system.web:
<httpRuntime executionTimeout="3600" maxRequestLength="1536000"/>
In machine.config:
Inside system.web, changed:
<processModel autoConfig="true" />
to:
<processModel autoConfig="true" responseDeadlockInterval="00:30:00" responseRestartDeadlockInterval="00:30:00" />
and in MetaBase.xml:
Changed:
AspMaxRequestEntityAllowed="204800"
to:
AspMaxRequestEntityAllowed="200000000"
When the upload fails, I get a 404 error from IIS. My web form does not begin processing, or at least, it doesn't make it to the Page_Load event. I threw an exception at the beginning of that handler, and it doesn't execute at all on large files.
Everything works fine with smaller files (I've tested up to about 5.5MB). I'm not exactly sure what file size is the limit, but I know that my limit needs to be higher than 150MB, since this is not the largest file that the client will need to upload.
Can anyone help?
Urlscan was active on all websites, and has it's own request entity length limit. I wasn't aware that Urlscan was running on our server because it was a global ISAPI filter, not running on my individual website.
Note: to locate global ISAPI filters, right click on the Web Sites folder in IIS Admin and click Properties, then on the ISAPI Filters tab.
(A note for googlers):
For IIS7 add below to web.config (I added above <system.serviceModel>):
<system.webServer>
<security>
<requestFiltering><requestLimits maxAllowedContentLength="262144000" /></requestFiltering> <!-- maxAllowedContentLength is in bytes. Defaults to 30,000,000 -->
</security>
</system.webServer>
When we ran into this issue we had to increase the buffer size limit according to this KB article:
http://support.microsoft.com/kb/944886/en-us
I know this mentions ASP, but I believe it worked for ASP.NET as well.
Edit: Here is a link that might be more relevant to your issue and provide other options:
http://weblogs.asp.net/jgalloway/archive/2008/01/08/large-file-uploads-in-asp-net.aspx
404 and missing Page_Load: IIS can only process the request once the complete POST is on the server. Therefore, if the POST fails (due to its size), it cannot fire the page's events.
You might try NeatUpload http://www.brettle.com/neatupload.
From the Manual: "By default, NeatUpload does not directly limit the size of uploads."
You can also try Velodoc XP Edition which has several advantages over NeatUpload including the fact that it uses ASP.NET Ajax extensions. See also the Velodoc web site for more information.
You say:
But 1536000 is only 1.5MB?

Resources