unable to browse asp.net mvc 4 page - asp.net

I'm not sure what I did, and this just happened today.
I am unable to browse one of my MVC 4 applications, which I was previously able to do.
There's no error message.
When I right click on my project and view in browser, it just shows "Connecting..." - localhost:55223, and it remains there like forever.
I have tried the following:
1) Copied the proejct onto another PC and browse - works!
2) Create a new MVC application in visual studio and browse - works!
I have set a breakpoint in global.asax's start method, and it doesn't even get there.
What else do I have to check?
Please help

Have you tried right clicking on the IIS icon in you taskbar and exiting it? Then build the project again to restart IIS.

Sorry I cannot comment because i am unable to see comment button.
See your global.asax RegisterRoutes method is it fine? for example:
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
name: "GridPaging",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional}
);
}

Related

ASP.net "{Controller}/" returning 403.14 error

I am having a curious issue with one of my projects in development. The issue is with links to a certain URL "//localhost:62168/Images/Index". I have buttons linking to that URL but when "//localhost:62168/Images/" is accessed it returns a HTTP Error 403.14 - Forbidden error. See the below Image:
localhost//Images/
Oddly enough though, when I enter the URL exactly ("localhost:62168/Images/Index") it loads the page properly. See the below Image:
localhost/Images/Index
I've done plenty of research online and I believe it may be an issue with routing so below I've added the code of my "RouteConfig.cs" file. Unfortunately, I am new to ASP.net and MVC and not knowledgeable on proper Routing procedures:
using System.Web.Mvc;
using System.Web.Routing;
namespace ReedHampton
{
public class RouteConfig
{
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
}
}
}
I've also tried multiple other "solutions" presented in other online forums to no avail. These include:
Adding "directoryBrowse enabled="true" " to web.config
Running "C:\windows\Microsoft.NET\Framework64\v4.0.30319> aspnet_regiis.exe -i" in Command Prompt
Going through IIS Express and registering IIS Express and ASP.Net
I would greatly appreciate any help that anyone can provide!
IIS will attempt to short-circuit the request if it finds something on the filesystem that matches the URL. In other words, I'd assume you have an Images directory in your document root. Therefore, IIS will attempt to hit this directory, rather than pass the request on to the ASP.NET machinery. Since you've disabled directory browsing, you get a 403.
Long and short, you need to keep your ASP.NET MVC routes unique from what you have physically in your document root. You could change the name of the Images directory to something like img, or put it in a parent folder like the default of /Content/Images. Otherwise, you'll need to change your controller name or create a custom route to that controller not called /Images.

Unable to change nopCommerce default start page

I am trying to get my nopCommerce 3.50 site to open a specific page when the site is visited.
When I debug the project locally it works correctly as I have the specific page 'welcome.html' set as the start action in the project properties (in Visual Studio 2012). However once the site is published on the server it ignores this request.
In IIS I have checked that 'welcome.html' is at the top of the list of default pages, however nopCommerce ignores these settings (as found on various forums) and even if you delete everything else it always goes to default.aspx.
I've tried adding this to the web.config in system.webserver and this has made no difference:
<defaultDocument>
            <files>
                <add value="Welcome.html"/>
            </files>        
</defaultDocument>
There is no other reference to a default starting page in the config.
I'm not too familiar with nopCommerce or the routing, does anyone know how/where I can change the default page? Everything I have found on the forums so far has not worked. And yes, I have rebuilt the project after each change, usually completely replacing the bin folder on the server to make sure.
I don't want the site to redirect to a specific action or view, but to a static HTML document in the root folder of the project (well I don't want that either really but the client has been very specific about what they want). The static page has two buttons, one that will go to the nopCommerce default.aspx and one that goes to another site.
Thanks
you can change the route in the global.asax.cs
Default route is
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Home", action = "Index", id = UrlParameter.Optional },
new[] { "Nop.Web.Controllers" }
);
This route will tell you execute in the HomeController, there is Index action (function) and return the view defined with the same name under the Views. View path will be Views/Home/Index
In order to change that you should add a welcome function (just copy the Index function and rename with welcome and paste it into the HomeController).
then you can change your routing as bellow.
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Home", action = "Welcome", id = UrlParameter.Optional },
new[] { "Nop.Web.Controllers" }
);
Dont forget to create your Welcome view under Views/Home as Welcome.cshtml
Found a way round it to meet the requirements:
Add a new folder into the directory ('NOP' for example) and put everything apart from the welcome.html page inside the new folder.
Change the links in the welcome page to point inside the new folder structure (images, links etc.).
In IIS make sure that welcome.html is set as a default document, and as it is now the only document in the folder it loads correctly.
In IIS convert the new folder into an application (right click > 'convert to application' on Windows Server 2012 R2)
This way no changes are needed to the code in nopCommerce and the desired result is achieved.

How to change default route in asp.net web api

I am working on asp.net web api. I am trying to set the default route for my project in global.asax file like,
localhost:45678/api/Products
But i didnt find any format similar to asp.net mvc route model like
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
It always redirects me to Home page(HomeController). please guide me.
Check your your RouteConfig class in your App_Start folder. You should see the default route below which you can change.
routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{id}",
defaults: new { id = RouteParameter.Optional }
);
EDIT
After reading your comments, I think the problem is not with your routes. I'm not sure why you would want to do it, but you just need to specify the Start URL for your project. Right click your web project - click Properties - click the Web tab - under Start Action select Start URL and enter http://localhost:45678/api/Products in the box. Save your project and run again. It should start at the new location.
The issue might be the common mistake that nearly lots of people get into.
The fact here is that the all routes get collected under System.Web.Routing.RouteTable.Routes collection regardless of the framework you use. So, if you put the ASP.NET MVC default route before the ASP.NET Web API route, the ASP.NET Web API route will never be scanned because the MVC route will be a match.
I am assuming this is the case here by looking at what you've provided so far. If that's not the case, upload the full solution out there somewhere and people can have a full look.
Actually if we are in the position to set the default route in properties->web->start location. then what is the need of route tables, custom routes,RegisterRoutes in global.asax file. I tried for this way
at first it seems like,
routes.MapHttpRoute(
name: "Default Api",
routeTemplate: "api/{controller}/{id}",
defaults: new { id = RouteParameter.Optional }
);
Now i want to make localhost:xxxx/api/products as default route for my web api then,
routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/Products/{id}",
defaults: new { controller = "Products", id = RouteParameter.Optional }
);
But the results of no use.
While developing in Visiual Studio, you can set it by expand the Properties folder of the project. Then open launchSettings.json file and look for "launchUrl" property in this file
You can change the default launch route for the profile you are working on.
"launchUrl" : "api/products"
[EDIT: My answer is the same as Kevin's]
Are you saying that when you run the project from Visual Studio, it opens a browser to the project home page?
The Web API project template contains an MVC controller plus a Web API controller.
The URI "http://localhost:xxxx/" goes the MVC controller, while "http://localhost:xxx/api/products" goes to the API controller.
When you run the project in Visual Studio, it will navigate to "http://localhost:xxxx" by default. In normal operation, a client would request whichever URI it wanted.
You can change the Visual Studio settings under Project Properties / Web / Start Action.
I think you have danced around the solution but just missed the mark. Try this:
Make sure you are calling GlobalConfiguration.Configure(WebApiConfig.Register); in your Global.asax.cs.
In WebApiConfig.Register() Set the default route as:
routes.MapHttpRoute(name: "DefaultApi",
routeTemplate: "api/{Controller}/{id}",defaults: new { controller = "Products", id = RouteParameter.Optional });
In your web project settings make sure you have "Start Url" property set as:
localhost:45678
Good Luck.
In my ASP .NET Core Web API project, whenever you DEBUG the project, it fires up a browser to a predefined URL. This can be configered by right-clicking the project and going to properties and then Debug tab as shown below.
That said, not sure what the difference is between this and the launchsettings.json described in a previous answer above.
You need to add:
Response.Redirect("Products.aspx");
to method index() in the class HomeController.

Index.aspx in a hybrid ASP.NET / ASP.NET MVC application

I have a hybrid asp.net and asp.net mvc3 application. It was originally just ASP.NET. The default page is still in ASP.NET and when a user goes to http://mysite.com/ I want the index.aspx to come up. Of course, the routes.MapRoute("Default", "{controller}/{action}/{id}", new { controller = "Home", action = "Index", id = "" }) line in my global.asax ir rerouting tht to my MVC pages.
I tried the following but neither of them worked:
routes.MapRoute("DefaultPage", "/", "~/Index.aspx");
routes.IgnoreRoute("{resource}.aspx/{*pathinfo}");
Does anybody know what I should be doing?
To map the root to Index.aspx you need to use MapPageRoute, rather than MapRoute, as follows:
routes.MapPageRoute("DefaultPage", "", "~/Index.aspx");
routes.IgnoreRoute("{resource}.aspx/{*pathinfo}");
Also ensure these lines are placed prior to the default route mapping.

ASP.NET MVC 2 site not loading after having moved to production. Setup appears to mimic QA fine. Thoughts?

I've setup an ASP.NET MVC 2 site several times on our test system on IIS 6. I'm fine with having to use the .aspx extension on controllers. The Global.asax.cs file looks like this:
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.html/{*pathInfo}");
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
"Default",
"{controller}.aspx/{action}/{id}",
new { controller = "Account", action = "LogOn", id = UrlParameter.Optional }
);
routes.MapRoute(
"Root",
"",
new { controller = "Account", action = "LogOn", id = "" }
);
}
Other than this, deployment is pretty basic. I copied the files to the server, created a new virtual directory in IIS, set Account.aspx as the default document, and clicked ok.
Repeating these same steps for production doesn't work. It seems like IIS 6/ASP.NET doesn't want to route correctly (even thought it did so just fine on our test server).
My url looks like this:
http://_server_name:90/<IS APPLICATION NAME/Account
The site load with the basic IIS 'site cannot be found'. The url has been changed to look like:
http://_server_name>:90/IIS APPLICATION NAME/CustomErrorView?aspxerrorpath=/_APPLICATION_NAME_/Account.aspx/Logon
(underscores begin and end place holder values and are not literally in the url).
CustomErrorView is a view I created for custom errors to forward to (including 404's).
Both servers are running windows 2003.
Any thoughts?
Try making a Webform page that just redirect to your path!! And configure iis to point that page!!!! Let me know if was this scenario
Okay, I'm an idiot. When deploying an asp.net mvc application, it helps to ensure mvc is installed on the server. I installed it through the web platform installer and, presto, everything worked.
Sorry about such a lame question. I was moving to production and the steps I just knew should work didn't work and I sort of panicked.
Thanks for your input Marco. Haven't had a chance to try that solution, but its running now.

Resources