my localhost IIS display me my project files - asp.net-mvc

I try to launch or browse my asp.Net mvc project on IIS, and he gives an error 403- forbidden, I solved this problem with enable the Directory Browsing, but after that he displays me my folders of the project.
The error

It's because of no default page in your directory refer below article
https://www.c-sharpcorner.com/UploadFile/francissvk/set-default-page-for-a-website-in-iis421/
If you having MVC application then you need to set default route and make sure you have MVC framework installed on the server
'routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters*
new { controller = "Home", action = "Index",
id = UrlParameter.Optional }
);'

Do you have the correct default documents set in IIS?
Open IIS (Windows key+R and type inetmgr)
Select the Default Documents option
Enter the default page name in the order you want IIS to check (index.html index.php index.py etc)
Disable Directory browsing :)
Now when the root of a folder is accessed without a direct page, it will check all the default names you have specified and display the one that it sees first.
See this link:
https://tecadmin.net/set-default-document-in-iis/

Did you get 403.14? I think your problem is IIS asp.net extension haven't been installed from "Add role and feature" or turn windows features on or off.
So no handler would help to handle the MVC routing request.
https://learn.microsoft.com/en-us/iis/application-frameworks/scenario-build-an-aspnet-website-on-iis/configuring-step-1-install-iis-and-asp-net-modules
Once you enable the asp.net module, this issue should be fixed. MVC don't depend on either default document or directory browsing.
I also notice that both .release and .debug file are displayed in the root folder. So you just copy the whole project files to your IIS root folder right?
It is suggested to only publish release file to the root folder with VS web deployment tool.
https://learn.microsoft.com/en-us/aspnet/web-forms/overview/deployment/visual-studio-web-deployment/deploying-to-iis

Related

How change default url (remove subdirectory) for MVC application

Just deployed ASP.NET MVC5 web application to IIS 10. To do this, under "default website", I created a new application ("Add application"). I had to put in an alias so I put in "xyz".
So, now the public url is similar to http://xyz.mysite.com/xyz .... but I want it to be only http://xyz.mysite.com (remove 'xyz' subdirectory).
How can I do this?
The problem is that my ajax calls are failing because of the subdirectory.
You can do either of the following:
Option 1:
Add Website in your IIS (instead of Add Application) and use the SNI feature. All relative path will be from root (/) level.
or
Option 2:
Modify your AJAX calls to use #Url.Action("actionName", "controllerName") so your URLs will be generated properly based on relative path. I suspect you are hardcoding actionNames to "/controllerName/actionName" which uses root as your relative path.

how to set default document in web.config file in ASP.NET MVC application..?

I'm working on ASP.NET MVC application it is working fine now i want to host it on IIS server, I'm doing this as generic procedure when I'm opening it on browser that time it showing all directories list what now how can set my default action in web.config file.
You don't set a default document with MVC. There's no such thing as documents in MVC, let alone a default one. If you're getting a directory listing instead of your app being loaded, then there's some problem with your setup. Most likely, you don't have it as an actual application in IIS, but just a virtual directory

Running MVC application on IIS without domain

My application contains lots of links to the root ("/login/dologin"). When I'm running the application under a domain, there's no problem.
Right now I'm moving to a new server, and I can't test my application. My application sits in "localhost/md", I need the link to go to "localhost/md/login/dologin". Instead, it goes to "localhost/login/dologin", and, ofcourse, the resource cannot be found.
What do I need to configure on my IIS to make this works without domain?
Thanks.
It's just a guess, since you haven't posted any of your configuration.
In your authentication element in the web.config, do you have the route to the login page specified as /login/dologin? could you try ~/login/dologin
The second option, should give you a relative path from the home of the virtual directory application, rather than going to the root of the 'site'
For referencing files (e.g. javascript & css) you could do #Url.Content("~/path/to/file.js")
EDIT: Based on additional comments
in Layout.cshtml...
var SITE_ROOT = '#Url.Content("~/")'
then in your JS file use SITE_ROOT as a prefix in your routes
var url = SITE_ROOT + "Home/Index";

Using Cassini with a virtual path that contains dots

I am working on an existing project in ASP.NET witch is based in a folder that contains dots
http://localhost/My.Awesome.WebClient/
This setup works fine using the integrated Visual Studio Develompent Server, but fails when I add MVC content and try to access it (Error 404 Resource not found).
http://msdn.microsoft.com/en-us/library/ee941656.aspx seems to explain the issue:
If you create a file system Web site in Visual Studio 2010 and the Web site is in a folder that contains a dot (.) in the folder name, URL routing will not work reliably. An HTTP 404 error is returned from some virtual paths. This occurs because Visual Studio 2010 launches the Visual Studio Development Server (Cassini) using an incorrect path for the root virtual directory.
However, the project is a Web Project, not a Web Site, and it only failed when I started using MVC.
The problem can be easily reproduced:
File - New - Project - ASP.NET MVC 3 Web Application
Edit project settings, Web: Use Visual Studio Development Server
Set the virtual path to something that contains a dot
Try to run the site
Is there a way to get this to work, besides using IIS instead of Cassini?
Edit:
I did find a workaround just now. It does not really work in a deployment scenario, but it may help in finding a solution:
in my Global.asax.cs file:
routes.MapRoute(
"Default", // Route name
// Notice that I added the virtual path here
"My.Awesome.WebClient/{controller}/{action}/{id}", // URL with parameters
new { action = "Index", id = UrlParameter.Optional } // Parameter defaults
);
// This is also new
routes.MapRoute(
"Root", // Route name
"", // URL with parameters
new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
);
Using this workaround, my MVC-Sites work, but only with the following url:
http://localhost/My.Awesome.WebClient/My.Awesome.WebClient/
If you don't get an answer to this question (personally, I'm not aware of any way around this), I would recommend using "IIS Express", which is available as a free download. It can be installed on development machines and you can control a lot of server settings with your web.config file, which is fairly unobtrusive.
You can download it here:
http://www.microsoft.com/download/en/details.aspx?id=1038
I use IIS Express exclusively now; Cassini has always lacked features and IIS Express avoids me having to configure IIS for each web application.

ASP.NET MVC and IIS 5

What is the best way to get hosting of an ASP.NET MVC application to work on IIS 5 (6 or 7). When I tried to publish my ASP.NET MVC application, all I seemed to get is 404 errors. I've done a bit of googleing and have found a couple of solutions, but neither seem super elegant, and I worry if they will be unusable once I come to use a shared hosting environment for the application.
Solution 1
Right-click your application virtual directory on inetmgr.exe.
Properties->Virtual Directory Tab-> Configuration.
Add a new mapping extension. The extension should be .*, which will be
mapped to the Executable
C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll,
or the appropriate location on your
computer (you can simply copy this
from the mapping for .aspx files). On
the mapping uncheck "check that file
exists".
3 X OK and you're good to go.
If you want, you can apply this setting to all your web sites. In
step1, click on the "Default Web Site"
node instead of your own virtual
directory, and in step 2 go to the
"Home Directory" tab. The rest is the
same.
It seems a tad hacky to route everything through ASP.NET.
Solutions 2
Edit the MVC routing to contain .mvc in the URL and then follow the steps in solution 1 based around this extension. Edit: The original image link was lost, but here it is from Google's Cache:
Answer is here
If *.mvc extension is not registered
to the hosting , it will give 404
exception. The working way of hosting
MVC apps in that case is to modify
global.asax routing caluse in the
following way.
routes.Add(new
Route("{controller}.mvc.aspx/{action}",
new MvcRouteHandler()) {
Defaults = new RouteValueDictionary (new{ controller
= "YourController"} ) });
In this way all your controller
request will end up in *.mvc.aspx,
which is recognized by your hosting.
And as the MVC dlls are copied into
your local bin , no special setttings
need to be done for it.
I think either way you'll have to do Solution 1.
Consider the HTTP Request pipeline.
A request comes into IIS.
IIS checks port/host header to see if it has a web site set up to capture requests for that host header/port.
IIS investigates the file extension of the request (.php, .asp, .aspx) and hands it off to an ISAPI that can handle that type of request.
Only at this point does ASP.NET (or a PHP runtime) kick in. If IIS does't have that mapping then it'll never hand off the request to the ASP.NET runtime and the request will never reach your code. That's why you need that glob (*) mapping to the ASP.NET ISAPI.
ASP.NET MVC framework urls often end with no file extension at all. If you want these requests to get handled by ASP.NET (or some other runtime) you have to map all requests regardless of the file extension to that ISAPI (ie. aspnet_isapi.dll).
This is often also done for HttpHandlers that need to serve off media like .jpg, .gif. For the handler to be hit it needs to get mapped to your code even though .jpg isn't a "normal" ASP.NET file extension.
HTH,
Tyler
Run:
C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\aspnet_isapi.dll -i
This will reset IIS registry settings for aspnet user.
Create the virtual directory:
1. Right click on the directory you want to convert
select Properties
under Directory, select Create.
under Configuration, select Add.
for Executable insert:
C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\aspnet_isapi.dll
for Extension insert: .*
uncheck “Check that file exists”
under Documents add entry point file, ie: Default.htm, index.htm, Global.asax
under Directory Settings
select Edit...
select Anonymous access
uncheck Allow IIS to control password
uncheck Basic authentication
uncheck Integrated Windows authentication
under ASP.NET, make sure version = v4.0.30319
TAKE NOTE of User Name ie: IUSR_AVSJ82S
Set sharing permission of physical directory:
In windows explorer, go to the physical directory that was converted to a virtual directory.
Right click the directory name
select properties
under security tab, select Add
enter the IIS User name ie: IUSR_AVSJ82S click check name.
click OK
set permissions to Read and Write.
FYI:On server 2003 (developing an app that had to connect to the RPS), it didnt' allow me to add the extension .*, I used the alternate solution modifying the route clause, and that
worked.
Have you tried adding .aspx to the end of the controller name?
It worked for Stack Overflow question Where can I get ASP.NET MVC hosting?.

Resources