when I try to view ASP.NET website in browser I get the full list of files in the website folder. What could be the reason?Is there only one reason or there might be a lot?
That could happen if you have not specified a start page for your web application.
Right click on the web page you want to use as the default page and choose "Set as Start Page" whenever you run the web application from Visual Studio, it will open the selected page.
Refer to the following:
Set Default Page in Asp.net
Setting the default page for ASP.NET (Visual Studio) server configuration
EDIT:
If you are launching the site from within Visual Studio, you can set the default page by doing the following:
From this SO question answer
Right click on the web page you want
to use as the default page and choose
"Set as Start Page" whenever you run
the web application from Visual
Studio, it will open the selected
page.
You need to specify on the server (in IIS) what the default page is, and disable directory listing for the site.
See also:
Setting the default page & disabling directory browsing in ISS / Web.config
It could be any of the other cases mentioned in the answers OR
IIS by default looks for these files in the directory to serve in the given order if no file is specified.
Perhaps you have not specified a file, and turned on "Directory Listing"
Related
I have an ASP.net project I'm working on (1st time in ASP.net) however I'm curious to know how I would find which page is the page Visual Studio launches when I start debugging. Each time I search for this answer all the results simply tell you how to SET the startup page and not what the startup page actually IS. Basically - "What is the entry point"?
Currently my 'Start Action' when viewing the Project Properties is set to 'Current Page'. While I realize I can set a specific page or 'Start URL' I'm wondering what does 'Current Page' refer to? Basically I'm looking to know where I find the first line of code that is run when I begin debugging.
My initial thought was that it is looking for an aspx file named default.aspx but since my project has two of these files named default.aspx I guess it's pointing to the one residing with my other project files that sit at the root of my project.
Is this correct?
I think there is two question you are asking.
Firstly, where is the entry point for your MVC application? Well your entry point for debugging MVC application would be Application_Start in Global.asax.cs file
protected void Application_Start()
{
}
Secondly, the Start Action is Visual Studio enables you to specify what happens when you run your application.
Current Page – Enables you to run the page currently open for editing in Visual Studio.
Specific Page – Enables you to set a particular page to run. You can set the page here or you can right-click a page in the Solution Explorer window and select the menu option Set As Start Page.
Start External Program – Enables you to run an external program.
Start URL – Enables you to request a URL. This option is typically used when building a Web Services application.
Don’t open a page – Enables you to do nothing.
You can change the start page to a particular page. For example, if you want to request the URL /Blog/Show/23 when your application starts, then you can enter this URL into the Specific Page input field.
My site/application points to a folder called "site" with all permissions set up.
In that folder resides "home.asp".
Default document is "home.asp".
When I go to the domain, I get a "page not found".
If I capture that 404 error in IIS and tell it to redirect to "home.asp", everything works.
The problem with that is I don't want to redirect all 404's to home.asp.
I want the site to default to home.asp and find it.
Any ideas why this is happening?
Do I need to do something to the .Net side of things to tell it to
use the .ASP side of things by default?
Do I need to create a .aspx default page that redirects to my
"home.asp"? If so, what do I name that page?
As Diodeus indicated you should not try to redirect to a default page with a custom 404 error page that redirects, but rather by making sure your "home.asp" is added to the list of default documents within IIS.
This is thus an IIS configuration issue.
For instance for setting up default documents in IIS 6.0 this would be:
In IIS Manager, double-click the local computer, right-click the individual Web site folder, and then click Properties.
Click the Documents tab.
Select the Enable default content page check box.
Click Add to add a new default document to the list. (For you this would be your "home.asp")
Optional: Click the document you want to remove from the list and click Remove.
Click a document from the list and click Move Up or Move down to change the order in which default documents are served to client requests.
Click OK.
(From http://www.microsoft.com/technet/prodtechnol/WindowsServer2003/Library/IIS/dc6eb1b4-9028-4308-9935-52b64edfad36.mspx?mfr=true)
We have a asp.net app, in which index.aspx is the default document in the website, instead of default.aspx.
Index.aspx is set as start page in the project too. but when I am trying to open for example: http://localhost:2265/, 1st I was getting the default.aspx page, after I removed the default.aspx file from the solution, now I have the directory listing displayed.
I would like to get index.aspx when I am entering http://localhost:2265/, is that possible to be set in the project or only in IIS?
Thanks in advance and happy holidays, Laziale
This is controlled from the server, which could either be IIS or the development server that's bundled with Visual Studio.
If you're launching the app from within Visual Studio, then the controls can probably be found under the properties of the ASP web site/app that you're launching. You could also right click the page itself and select "Set As Startup Page".
All of this doesn't affect the behaviour of the app once it's hosted in IIS, however. You'll need to find similar settings in the IIS page - there should be many a tutorial on the web for that (I can point you to one if you're having trouble).
Hope this clears up the behaviour of default pages!
Just open your solution in VS, then select the page you would like to be the startup page and do a right click and select 'Set As Start Page' option
In your project right click on the page you want to be your landing page and click "Set as Start Page".
This will only work when you run it from Visual Studio though. If you want to do it once it's deployed you will have to use IIS or setup a redirect I believe.
Coding Platform ASP.NET 4.0 WebForms on IIS7.5
If I request a page blahblah.aspx which does not exist, I get navigated to my custom error page for Page not found Exception. I have implemented URL routing and so I have omitted all my .aspx extensions for routes.
Now, If I type www.mysite.com/blahblah (thats a url without extension) instead of going to my custom error page, it gets redirected to my IIS 404 error page.
What should I do to make my custom error page appear on my site instead of IIS error page?
The Easy Way
If your IIS 7 web server doesn't already have it, install the IIS 7.0 Administration Pack from Microsoft.
Navigate to the root web server name in IIS, and open the Configuration Editor (part of the Administration Pack). Change the dropdown to system.webServer/httpErrors, right-click on defaultPath, and choose 'defaultPath' Attribute -> Unlock Attribute.
Then try to change the custom error handler page again. Navigate to your site, open Error Pages under the IIS group, click Edit Feature Settings on the right, select Custom error pages and finally, put in your path for the default page.
No lock error this time.
I originally tried to unlock this attribute at the web site level but was prevented, so be aware you may have to go all the way to the root of the IIS tree, the web server itself.
The Manual Way
I know you can accomplish all this by direct editing in notepad of the appropriate config file on the web server. And that may be required for your particular web hosting environment or company production web server change protocols. But why make it complicated if it doesn't need to be? Plus, this way you can do it in the GUI, and compare the before and after to see what changes you truly have to make. But if you MUST do it manually, then:
Open the file %windir%\System32\inetsrv\config\applicationHost.config in Notepad. Run Notepad as administrator if you're having problems.
Pro tip: Do not use notepad++ to edit applicationHost.config. You'll end up secretly and silently saving a 32-bit copy of the file that's in a different folder than the one IIS looks in (due to Windows, not np++) without actually affecting the file you wish to change.
You'll see something like this:
<httpErrors lockAttributes="allowAbsolutePathsWhenDelegated,defaultPath">
Remove the ,defaultPath section and save.
You will be able to make the changes you need.
Assuming you haven't done this already...
Go to IIS, select your website, and choose the option "Error Pages". In there, find the 404 status code, right click and go to "Edit Feature Settings". you can then select "Custom Error pages" and change the "Path Type" to URL "Execute URL" to do some rewriting, or a default redirect page for anything else. Put in your URL as a relative value, and now it should redirect to this url on 404 errors.
Edit: Did a bit of digging, in cases, this config may be locked, if you run the following command, it should remove the lock:
%windir%\System32\inetsrv\appcmd unlock config -section:system.webserver/httperrors
Once that is done, you can edit the url properly.
If I set page "MyPage.aspx" as the start page, do I also need an index.html file?
Thanks.
Setting a page as a start page in Visual Studio only affects what page is loaded when you launch from the VS IDE. You'll have to configure IIS when you deploy if you want "MyPage.aspx" to be the default page that loads once your site is in production.
No you don't need, but you need to set your start page "MyPage.aspx as startup also on IIS.
As the above said , simply no. setting default page from IDE will automatically make it as default page. Only you have to do some settings in IIS that is from the properties of the web application, go to the tab where the default pages are displayed. Add the name of the page you have set from the VS IDE.