I am trying to publish my mvc web site on the localhost through visual studio but the problem is when i browse to the the localhost in the browser it gives me a directory listing page. here is the screen shot of publish dialogue. Can somebody please guide me through the process i have been searching for the whole day but couldn't get it to work
here id the global.ascx
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("Facebook",
"XdReceiver",
new { controller = "Account", action = "XdReceiver" });
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);
}
}
Do you have a requirement to use WebDeploy for your publish? If not, you could create a directory and point IIS to that directory and change your publish method to File System.
IMO, WebDeploy is overkill for localhost deployments if you're using it simply for testing. WebDeploy becomes very useful for network deployments since it compares the contents of the directories and maintains which files have been updated and which ones have not.
just create a empty site using IIS. and then publish the site in visual studio using the File System publish method.
Try checking the "Mark as IIS application on destination" option.
Also, try publishing to Default Web Site/Rental and accessing it as http://localhost/Rental.
If you installed IIS after installing .NET, did you run aspnet_regiis -i? And could you please post your Global.asax file with MVC routes?
Related
I am converting an asp.net webforms website type project to an asp.net mvc web application. I want to keep all the changes to a minimum.
The pages and its subfolders are right at the top of the project folder and there are hundreds of them.
Now, in the new web application, I want to move them to a subfolder, let's call it WebForms.
Is there a way at runtime to run the pages as they ran before, i.e. at the root of the application folder?
Before I had: http://localhost:54321/Page1.aspx. Page1.aspx was stored in the website project root folder.
In the new project structure I have the disk:
<project folder>
WebForms
Page1.aspx
This works: http://localhost:54321/WebForms/Page1.aspx, but I want to somehow map it to http://localhost:54321/Page1.aspx.
Is it doable? I use IIS Express for development and IIS 7.5 for test/production deployment. I want to avoid having to change the image and other content urls - as you can imagine moving the pages to the subfolder breaks some of them.
Thanks
If you just want to map all requests to /something.aspx so they go instead to WebForms\something.aspx, you can probably just use the following route rule.
routes.MapPageRoute(
"Other Web Pages",
"{pagename}.aspx",
"~/WebForms/{pagename}.aspx");
Alternately, if you need more advanced scenarios, you could use a custom class that derives from RouteBase and use a RegEx to match for and map the route, similar to this question's answer
public class WebFormsRoute : RouteBase
{
Regex re = new Regex(#"^/(?<page>\w+)\.aspx", RegexOptions.IgnoreCase);
public override RouteData GetRouteData(HttpContextBase httpContext)
{
var data = new RouteData();
var url = httpContext.Request.FilePath;
if (!re.IsMatch(url))
{
return null;
}
var m = re.Match(url);
data.RouteHandler = new PageRouteHandler("~/WebForms/" + m.Groups["page"].Value + ".aspx");
return data;
}
}
And then add it to your route collection in RouteConfig
public class RouteConfig
{
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.Add(new WebFormsRoute());
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
}
}
i have inherited an application that is both clasic asp.net web forms and mvc (started as web forms project). I would like to setup routing like MVC. What is the best way to go here? All i need is a push in the right direction.
I know how to setup routing for the MVC only project via global.asa > App_Start > Route Config and area registration cs files.
Environment:
VS 2012, IIS 7, ASP.NET 4.0, classic asp.net web forms and MVC 4.
My thinking:
I am thinking about doing some thing like following, do you guys see an issue here? I may end up with some web.config issues but at this this time i am not sure what those would be. I need your advice to properly setup the structure here.
Global file addition:
protected void Application_Start()
{
RouteConfig.RegisterRoutes(RouteTable.Routes);
}
App_Start > RouteConfig.cs
namespace My.Site
{
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 string[] { "My.Site.Controllers" }
);
OTHER ROUTES WILL GO HERE, THESE MAY REDIRECT TO a webform page or to a controller action.
}
}
}
Going through the following to setup all properly.
http://www.hanselman.com/blog/PlugInHybridsASPNETWebFormsAndASPMVCAndASPNETDynamicDataSideBySide.aspx
http://www.hanselman.com/blog/IntegratingASPNETMVC3IntoExistingUpgradedASPNET4WebFormsApplications.aspx
http://www.packtpub.com/article/mixing-aspnet-webforms-and-aspnet-mvc
http://msdn.microsoft.com/en-us/library/dd329551.ASPX
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.
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.
I have an existing web site setup on my local IIS built with web forms setup in this format:
-MainSite
-Application1
-Application2
-Application3
There are separate applications in each location, so MainSite has an application, and Application1 has another application and so on. This way development on different applications in the same site can be broken out. I want to add a new Application that is MVC instead of web forms. I created a new MVC project which runs in Cassini just fine, but when I create a new IIS application for it and point it to the MVC project I am unable to navigate to it in the browser and get a 404 error. I am expecting to be able to navigate to http://MainSite/NewMVCApplication/. I want the root of NewMVCApplication to point to my Contacts Controller.
My global.asax in the new MVC application currently looks like this:
public class MvcApplication : System.Web.HttpApplication
{
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
"Root", // Route name
"", // URL with parameters
new { controller = "Contacts", action = "Index", id = "" } // Parameter defaults
);
}
protected void Application_Start()
{
RegisterRoutes(RouteTable.Routes);
RouteDebug.RouteDebugger.RewriteRoutesForTesting(RouteTable.Routes);
}
}
Make sure NewMVCApplication is running in an integratedMode pipeline application pool.