Hybrid MVC and Web Site application - asp.net

I evaluating the MVC framework for my existing application. Trying to write a sample applicaiton where I need to navigate from MVc view to .aspx files and vice versa. The application does seems to be working. Not able to figure out where I am going wrong.
I have set up wild card mapping
I have set up .mvc mapping
I am using IIS6
I am using VS2008 with SP1
I added Controller directory to App_Code
I added Views directory to the web site application
MVC does not seem to be working well with web site application.
I do not know where to activate .mvc ? I do not know where to write the following code
HttpContext.Current.RewritePath(Request.ApplicationPath, False)
Dim httpHandler As IHttpHandler = New System.Web.Mvc.MvcHttpHandler()
httpHandler.ProcessRequest(HttpContext.Current)
HttpContext.Current.RewritePath(originalPath, False)
Can some one help me? I do not know how can I give my code so that you could review that.

This code would go into the Page_Load method in the code behind of the Default.aspx in the root directory.

Related

Using a view specific connection string in ASP.NET MVC

I upgraded an old website from ASP.NET to MVC recently and now I am running into a user login problem with one of my views. In the old situation I would have a separate web.config in the folder for that page that would set the connection string specifically for that page. Now I would like to do that in ASP.NET MVC as well, however the web.config in the specific views folder does not work. I also tried to change the web.config in the views folder, but maybe I did this in a wrong way because it did not work.
Does anyone have an idea how to accomplish the same result in ASP.NET MVC as I had in ASP.NET?
Why not use a separate configuration file, as explained in this MSDN article?
https://learn.microsoft.com/en-us/dotnet/framework/data/adonet/connection-strings-and-configuration-files

Best way to intregrate ASP.NET MVC with ASP.NET? [duplicate]

Is it possible to create a MVC root application (Portal with masterpages and themes) and add a couple of WebForms based subprojects (we already have an existing WebForms application that we would like to integrate into the Portal)?
How would you centralize navigation (sitemaps, url routing)?
How would you share the masterpages?
How would you refer to resources (~ issues etc.)?
Combining web forms with MVC is entirely possible. See this blog post by Scott Hanselman for an introduction.
Sharing master pages: see this StackOverflow question
routing: In ASP.Net 4.0, routing has been enabled for web forms page routes (scottgu's blog)
For reference I managed to accomplish this task yesterday - add MVC functionality to an existing WebForms website, that is - so thought I would write in case it is of any use to anybody.
People say: "the best way is to rewrite your web forms application as MVC" but there is often no business case for this when the application is well established and has grew over time to be quite a monster (that still works well I might add). In my case, we had been asked to implement a new function into this application - and having been developing in MVC on other projects recently - I wanted to build this new function in MVC. This is what I did:
Create a new ASP.NET MVC 4 Application and selected the Empty Template (with Razor)
Once loaded, right-clicked References > Browse and then navigated to the Bin folder of my existing website. I then added in the DLL's I was using in the existing site. For reference, I am using AjaxControlToolkit so decided to add in the latest one from NuGet. This should then auto-update the web.config file
I then opened up Windows Explorer and navigated to the root folder of my existing website. Using Visual Studio, I then replicated the top-level folder structure of the existing site (minus the Bin folder) resulting in the 2 sites having the same top-level folders (but the new project having the MVC App_Start, Controllers, Models and Views folders also, but not Bin obviously).
Once setup, I copied the sub-folders and files from the corresponding top-level folder in Windows Explorer and pasted them into the solution. If you do it the way, the project allows you to copy in sub-folders and content directly, adding existing item via visual studio only copies in files thus saving time. Please note: for the root folder, I did NOT copy in web.config or Global.asax, but copied in all other files (like default.aspx, etc)
Once all content was copied, I opened up web.config in the new project and web.config in the existing site. I copied into the new web.config anything specific to the existing website (appSettings, connectionStrings, namespaces, membership info, etc). The same applied to the Global.asax files.
I attempted a build and fixed anything I'd missed.
Once everything was right (and I had shot down a few Yellow screens of death) I noticed that I got the page not found error when loading default.aspx. This is down to routing, here is the changes I made to the Routing info (located in Global.ascx MVC 3, or App_Start > RouteConfig.cs MVC 4):
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
// This informs MVC Routing Engine to send any requests for .aspx page to the WebForms engine
routes.IgnoreRoute("{resource}.aspx/{*pathInfo}");
routes.IgnoreRoute("{resource}.aspx");
// Important change here: removed 'controller = "Home"' from defaults. This is the key for loading
// root default page. With default setting removed '/' is NOT matched, so default.aspx will load instead
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { action = "Index", id = UrlParameter.Optional }
);
}
With all these steps taken, the site loaded and ran as it always did, but I now have a ASP.NET WebForms and MVC hybrid. I am sure there are probably easier ways of accomplishing this task, but I tried other methods and failed. This way took me around 20 minutes and I was up and running... well sat and coding :)
Great answer above. The other thing you could consider is migrating from ASP.NET to ASP.NET MVC, in which case this post might help you migrate the project files.
I was too stucked in this situation, after all i got a solution which worked, first of all copy web.config in your views folder.
After that open Route.config(Routeconfig) file, there you will find one method RegisterRoutes, keep it as it is and create another method named RegisterRoutes2(), and copy paste the below method code from the mvc application:
public static void RegisterRoutes2(RouteCollection routes)
{...}
in some cases method name in mvc app would be RegisterRoutes.
If above code does not work, copy paste it from your machine’s mvc application.
Then, go to global.asax file, ther you will find RegisterRoutes() has been called, simple now , also call RegisterRoutes2().
And you are done, restart your application, or clean build, it will run.

How to publish mvc3 applications?

I'm busy making a CMS using MVC3. I want to test the current build on the live server. Now, with a normal html website, you'd have a index.html or index.php and i think asp gives a default.aspx. But I don't have anything like that in my project. Can anyone tell me where to get a default page, or how to make one, I have no idea what the format/syntax would be...
This link might help:
http://msdn.microsoft.com/en-us/library/dd410407(v=vs.90).aspx
And a possible duplicate of this one:
Publish ASP.NET MVC Application : read configuration file permissions
and this
How to publish aspnet.mvc site?
The default page is defined by your routes and your views.
Look for something like /Home/Index.aspx which is what will be served up when going to www.domain.com
To do a simple publish use the Publish workflow by right-clicking your ASP.NET MVC project in Visual Studio and select Publish

WebService on IIS with IIS-Manager

I just created a simple test WebService with Asp.net called
MyWebService.asmx
I can't access it from exteriour, cause Visual Studio don't allow this..
So I wanted to make a own IIS Webserver to host my Webservice, but
how do I add my "MyWebService.asmx" to the IIS with the IIS-Manager?
Hope someone can help me.. Google didnt help me a lot
You have to publish this WebService (right click on the project -> Publish) and host it using IIS like a regular Web Application.
Just create a new application, as you would do if you create a "real" ASP application
put, for completeness and to be sure the app is running a default.aspx into the root dir, which says something like "app is running!"
put the ASMX file into the directory (i think it will be place in the APP_CODE directory, but i'm not sure 100%)
config your webservice in the global.asax, without it nothing will happen (hint: also configure the help page for webservices, otherwise users accessing it will get the interface description in the browser)
A longer description of that can be found here: http://msdn.microsoft.com/en-us/library/8wbhsy70%28v=vs.80%29.aspx

Get Flex modules from ASP MVC

We´re developing an ASP MVC application witch the View (aspx) has a Flex embed. This aspx/flex view is composed by a flex application and several modules.
So, when we call the application url (http://localhost:9090/MyProject/Flex/Index), the server invoke the method the will return the ActionResult that represents this action, in this case the ~/Views/Flex/Index.aspx (with the Flex app). However when the ModuleLoader, in the Flex application, try to load a module an error occurs. The problem is that the Flex application can´t directly access the modules folder (~/Views/Flex/modules/module.swf).
Are there any way to get the module through an ASP MVC action? Or the best approach is to allow the access to this folder through web.config?
Again, sorry for the poor english!
Thanks,
André
The views folder should be used for aspx/ascx views. You'll want to put .swf files in in a content folder like ~/Content/modules/module.swf.

Resources