0

I have the plan to code new content of our old asp.net website with MVC.

User want no discontinuity between old and new sites, so I have to use same solution and make page from old and new "Way" speak each other.

I follow this topic

but when I try to open page - I get "Error HTTP 404.0 - Not Found" exception.

What I do is:

  1. Add MVC to my web project with Nuget
  2. Edit web.config section to this
 <add assembly="System.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>
        <add assembly="System.Web.Extensions.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
        <add assembly="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
        <add assembly="System.Data.Services.Client, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
        <add assembly="Microsoft.Web.Infrastructure, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
        <add assembly="System.Web.Routing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
        <add assembly="System.Web.Abstractions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
        <add assembly="System.Net.Http, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>
        <add assembly="System.Web.Mvc, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
  1. Edit my global.asax to this:

    public class Global : System.Web.HttpApplication
    {
        public void RegisterGlobalFilters(GlobalFilterCollection filters)
        {
            filters.Add(new HandleErrorAttribute());
        }
    
        public static void RegisterRoutes(RouteCollection routes)
        {
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
            routes.IgnoreRoute("{resource}.aspx/{*pathInfo}");
            routes.MapRoute(
               "Home",
                // Route name
               "home/{action}/{id}",
                // URL with parameters
               new { controller = "Home", action = "Index", id = UrlParameter.Optional }
                // Parameter defaults
                );
        }
        protected void Application_Start()
        {
            RegisterGlobalFilters(GlobalFilters.Filters);
            RegisterRoutes(RouteTable.Routes);
        }
    }
    
    void Application_Start(object sender, EventArgs e)
    {
        ... my old code
    }
    
    void Application_End(object sender, EventArgs e) 
    {
        ... my old code
    }
    
    void Application_Error(object sender, EventArgs e) 
    { 
        ... my old code
    }
    
    void Session_Start(object sender, EventArgs e) 
    {
        ... my old code
    }
    
    void Session_End(object sender, EventArgs e) 
    {
        ... my old code
    }
    
    protected void Application_BeginRequest(Object sender, EventArgs e)
    {           
        ... my old code
    }
    
  2. Create HomeController in AppCode folder:

    using System.Web.Mvc;
    public partial class HomeController : Controller
    {
    
    
    protected override void Execute(System.Web.Routing.RequestContext requestContext)
        {
            base.Execute(requestContext);
        }
    
    public ActionResult Index()
    {
        var r = new ContentResult();
        r.Content = "Hello world";
        return r;
    }
    }
    
  3. This is what I get:

error

I have also tried this way but got same error.

I read this but it suggests migrating entire site to Web Application and I am afraid to do that...

Community
  • 1
  • 1
gt.guybrush
  • 1,320
  • 3
  • 19
  • 48
  • This might be something you've considered already, but why not have a separate MVC project, and then when you need to link from an "old" style page to a "new" style page just change the hyperlink on the old page to point at the new content. If you deploy them side-by-side on the same IIS it would probably be difficult for the user to see they are two different deployments – ADyson May 13 '16 at 08:15
  • is other way iam studyng with system administrator. if can be done using same port can be easy, if different port is needed can be problemtic due to security policy – gt.guybrush May 13 '16 at 08:24
  • why would you need a different port? Just the same port with a different IIS virtual directory. – ADyson May 13 '16 at 08:25
  • simply i don't know it very much :D iam waiting for some answer on how and if can be done – gt.guybrush May 13 '16 at 08:26
  • It's definitely possible to host several websites on the same IIS. And it's definitely possible to pass security information between them (if that's required), it just needs to be configured properly. I'm not an expert in exactly what is required but in my last job we had exactly that same setup - two website with links between them, passing session info between them, hosted in the same IIS on the same domain and port. They were just in different virtual directories. I think this will be much simpler than trying to mix MVC and Forms in the same project. – ADyson May 13 '16 at 08:53
  • get answer now, in few work: no. one site can have only one directory and one web config. any interaction between different sites is locked by security policy defined by security man. so only solution left is mixing them (or develop again as website) – gt.guybrush May 13 '16 at 08:55
  • If you mean "website" as defined by IIS, there's no need to have interaction between different sites, only between different virtual directories within the same site. However, if they are saying that each website can only have one directory and one web.config, then that's a problem for you. I cannot begin to imagine why your security people think that's a necessary or sensible policy, it sounds ridiculous to me and have never heard of anyone enforcing that before. But if those are your constraints you will have to work within them - sorry I can't help you more. – ADyson May 13 '16 at 09:07

0 Answers0