Unable to change nopCommerce default start page - nopcommerce

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.

Related

Change Default Page in ASP.NET Core Razor Page to Login Page

I am changing Default Page from /Home/Index to /Identity/Account/Login using ASP.NET Core Razor Page but it is always loading /Home page as default page.
services.AddMvc()
.SetCompatibilityVersion(CompatibilityVersion.Version_2_1)
.AddRazorPagesOptions(options =>
{
options.Conventions.Clear();
options.AllowAreas = true;
options.Conventions.AddAreaPageRoute("Identity", "/Login", "/Identity/Account/Login");
});
It should load the Login Page Model as default page. Please help me to solve above problem. Waiting for your quick response.
To map your site's root to the /Identity/Account/Login page in ASP.Net Core (v2.1 and above) you can follow these instructions:
Undo the changes you've made in the ConfigureServices() method. (I.e. .AddRazorPagesOptions(...))
Change the #page declaration at the top of the Login.cshtml template file to #page "/"
If you haven't already, delete the Index.cshtml and Index.cs page files.
Step 1 is for cleaning up.
Step 2 is to configure the Login to the root path /. (more info here)
Step 3 is necessary because if the Index page files are not deleted, they will be mapped by convention to the root path and will conflict with the changes in step 2. This will throw a AmbiguousMatchException when you browse to the root path.
The arguments of AddAreaPageRoute are areaName, pageName, route
For setting the default page in area Identity to /IdentityAccount/Login you would have to call
options.Conventions.AddAreaPageRoute("Identity", "/Identity/Account/Login", "");
If you want to set the page-wide default page you should call
options.Conventions.AddPageRoute("/Identity/Account/Login", "");
The default page is at route ""

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.

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.

ASP .NET MVC-3 route add/map to a virtual directory for an alias

I have followed Maarten Balliauw's post on domain routing. I had been able route to controller's for different sub-domains. But I don't know how to route to a virtual directory. As you see this is a sample example for routing to usual mvc controllers,
routes.Add("DomainRoute", new DomainRoute(
"home.example.com", // Domain with parameters
"{action}/{id}", // URL with parameters
new { controller = "Home", action = "Index", id = "" } // Parameter defaults
));
As my blog resides on Virtual Directory I need to add the route to this virtual directory named "~/blog"
I have tried code like this with no good result,
routes.Add("DomainRoute", new DomainRoute(
"blog.domain.com", // Domain with parameters
"blog", // URL with parameters
new { controller = "blog" } // Parameter defaults
));
If anyone can bring some light into this it will be amazing.
You could try to make the blog an MVC Area of your main web application. You create a new Area called blog. This creates a Folder called "Areas/blog" in your main webroot. You can then turn the 'blog' folder into a virtual directory pointing to your blog application.
I did this in a recent web project for my admin backend. I used this blog post and it worked great. Very simple and keeps your application nice and clean.
http://bob.archer.net/content/aspnet-mvc3-areas-separate-projects
When you are actually inside the 'blog' area your actionlinks and everything works like normal. You only need to add "Area = 'blog'" to your links that move you from area to area.
Once you create the blog area take a look at the routes file it creates. I hope that makes sense.
The implication here is that the virtual folder is completely distinct from the MVC application it's within -- if that's the case, do you need to use the MVC routing at all, since you don't need any of the MVC resources to begin with? It would probably be easier just to configure the subdomain to point at the appropriate folder within IIS, and bypass MVC's routing altogether.

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