asp mvc not show route and title in url after deploy - asp.net

I am developing a website with ASP.net MVC3.
I have built it up and ran normally at local. Then when I deploy it with IIS 7.5, the site can display. All functionality works except the url is not changing when I switch in between actions and controllers(the url always shows "www.mysite.com" not "www.mysite.com/home/action"). Also, the title of pages are not shown. Instead of my slogan, it shows the domain url like www.mysite.com on the page title of browsers.
I followed the official deploy instruction of ASP.net with IIS.
Is there anyone knows what's the problem? Thanks in advance.
Here is my code for the Global.asax
public class MvcApplication : System.Web.HttpApplication
{
public static void RegisterGlobalFilters(GlobalFilterCollection filters)
{
filters.Add(new HandleErrorAttribute());
}
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
"ImageWall", // Route name
"ImageWall/{action}/{id}", // URL with parameters
new { controller = "ImageWall", action = "Index", id = UrlParameter.Optional } // Parameter defaults
);
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
);
}
protected void Application_Start()
{
AreaRegistration.RegisterAllAreas();
RegisterGlobalFilters(GlobalFilters.Filters);
RegisterRoutes(RouteTable.Routes);
}
}

Regards the title, in your views, do you use something like
ViewBag.Title = "Some Title"
In the HTML source of a page on your site, does the <title> element get populated? If not, then that could explain why you do not see the title.
Regards the url, can you post the code of your global.asax.cs file please (or global.asax.vb if you're using VB.NET). That is where route configuration can take place, so seeing that could help us explain why the url does not a show.

I have found the problem.
The problem is caused by the settings of Domain.com. As I am a fresher to deploy, I didn't set the "A Record" for all my domains. I just set the redirection to my IP.

Related

How to set Login.aspx page as the default page in an MVC Application

I have added a aspx page in my MVC Application naming Login Page. But On Hosting it was not Setting as the default because the default page in IIS has been overridden by the route.config. How to set it aspx page in Route.config in an MVC application
On Hosting it was not Setting as the default because the default page in IIS has been overridden by the route.config
//I have Tried this and Its Working
public class RouteConfig
{
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
name: "Default",
url: "../Login.aspx"
//defaults: new { controller = "NOP", action = "Default", id = UrlParameter.Optional }
);
}
}
Follow the below steps and you are good to go:
Right-click your Project within the Solution Explorer.
Choose Properties.
Select the Web tab on the left-hand side.
Under the Start Page section, define the Specific Page you would
like to default to when the application is launched.
Save your changes.
Another way is to add authorization attribute to the controllers where you need to be logged in.
[Authorize]
public class somecontroller: BaseController
{
// ...
}

Trying to display Custom View in MVC app but it says requested URL not found

I am new to azure, MVC and also ASP.NET. I am writing MVC Cloud service with ASP.NET web role. Please help me with this problem
When I create the application there are default views but I wanted to see my view so I set my view as start page. I also changed the values in RegisterRoutes method
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "User", action = "AddUser", id = UrlParameter.Optional }
);
}
When I run the app, it gives HTTP 404 error because it could not find request URL : /Views/User/AddUser.cshtml
In MVC you don't put the view in the URL to get it rendered.
This won't work: /Views/User/AddUser.cshtml
As you've correctly put in your question the default route is {controller}/{action}/{id} with id being optional.
So assuming that User is your controller, i.e. you have a class called UserController, which looks something like:
namespace My.Controllers
{
public class UserController : Controller
{
which has an action on it called AddUser:
public ActionResult AddUser()
{
// implementation logic
return View();
}
Then the default route will display your view when it processes the URL /User/AddUser
In MVC 5, this looks something like:

URL Rewriting in Asp.net MVC 3

I am new to Asp.net MVC.
I am creating web application, where i have to rewrite url with product name.
I am not sure if that is possible or not in MVC.
Like,
http://sitename.com/category1/product1
http://sitename.com/category1/product2
will have same page.
There are facilities to generate friendly urls within MVC.
Check out the article at - http://www.asp.net/mvc/tutorials/older-versions/controllers-and-routing/asp-net-mvc-routing-overview-cs - for an overview of how this is handled in MVC.
Essentially, you need to configure the routes on application startup as follows. This can usually be done in the global.asax file but cna be split for areas etc.
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Home", action = "Index", id = "" } // Parameter defaults
);
}
protected void Application_Start()
{
RegisterRoutes(RouteTable.Routes); // Reigster the routes
}
This is the default route but you can define as required.

MVC 3 with IIS Express Odd Redirecting behavior

I have a simple MVC 3 webapp that's been giving me trouble lately - and nowhere I look seems to have any information that can help me. I've been having two issues that seem related in how they're behaving.
In development, it starts fine on localhost (http://localhost:53268/) and works for the index, but doing anything outside of that has IIS returning a 404, ignoring any redirecting to what should be a proper URL.
Now, in production, it behaves differently. Again, the index page works fine, it has the proper URL, but any other page (either through a link or going directly to the URL) redirects to localhost (https://localhost/). The odd thing is for me, it's working as it should be on development (giving me what I should be seeing when I usually get 404s), but on other machines it gives absolutely nothing.
I had inherited this from a co-worker who had since left, but had given me the advice of using IIS Express to get it working from the development side. This was already working in production before, but now... not so much.
EDIT
The global.aspx file
public class MvcApplication : System.Web.HttpApplication
{
public static void RegisterGlobalFilters(GlobalFilterCollection filters)
{
filters.Add(new ElmahHandleErrorAttribute());
filters.Add(new HandleErrorAttribute());
}
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
);
}
protected void Application_Start()
{
AreaRegistration.RegisterAllAreas();
RegisterGlobalFilters(GlobalFilters.Filters);
RegisterRoutes(RouteTable.Routes);
}
}
EDIT
Got it figured out. Turns out there were some issues with Web.Config and the server it was on getting the wrong one. Works fine now.

Setting the default page for ASP.NET (Visual Studio) server configuration

When I build and run my application I get a directory listing in the browser (also happens for sub folders), and I have to click on Index.aspx. It's making me crazy.
Visual Studio 2008
ASP.NET Development Server 9.0.0.0
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.
The built-in webserver is hardwired to use Default.aspx as the default page.
The project must have atleast an empty Default.aspx file to overcome the Directory Listing problem for Global.asax.
:)
Once you add that empty file all requests can be handled in one location.
public class Global : System.Web.HttpApplication
{
protected void Application_BeginRequest(object sender, EventArgs e)
{
this.Response.Write("hi# " + this.Request.Path + "?" + this.Request.QueryString);
this.Response.StatusCode = 200;
this.Response.ContentType = "text/plain";
this.Response.End();
}
}
Go to the project's properties page, select the "Web" tab and on top (in the "Start Action" section), enter the page name in the "Specific Page" box. In your case index.aspx
Similar to zproxy's answer above I have used the folowing code in the Gloabal.asax.cs to achieve this:
public class Global : System.Web.HttpApplication
{
protected void Application_BeginRequest(object sender, EventArgs e)
{
if (Request.Url.AbsolutePath.EndsWith("/"))
{
Server.Transfer(Request.Url.AbsolutePath + "index.aspx");
}
}
}
public class Global : System.Web.HttpApplication
{
protected void Application_BeginRequest(object sender, EventArgs e)
{
if (Request.Url.AbsolutePath.EndsWith("/"))
{
Server.Transfer("~/index.aspx");
}
}
}
One way to achieve this is to add a DefaultDocument settings in the Web.config.
<system.webServer>
<defaultDocument>
<files>
<clear />
<add value="DefaultPage.aspx" />
</files>
</defaultDocument>
</system.webServer>
If you are running against IIS rather than the VS webdev server, ensure that Index.aspx is one of your default files and that directory browsing is turned off.
This One Method For Published Solution To Show SpeciFic Page on startup.
Here Is the Route Example to Redirect to Specific Page...
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 },
namespaces: new[] { "YourSolutionName.Controllers" }
);
}
}
By Default Home Controllers Index method is executed when application is started, Here You Can Define yours.
Note : I am Using Visual Studio 2013 and "YourSolutionName" is to changed to your project Name..
I'm not sure what framework you are using but in ASP.NET MVC you can simply go to the App_Start folder and open the RouteConfig.cs file. The code should look something like this:
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 }
);
}
}
You can change the landing page on the last line of code there after defaults.

Resources