I know this is an old topic but i was wondering if a newer more elegant solution exists now. I am currently working with a legacy asp.net application and we are adding an MVC project to it. In order to keep uniformity we have been tasked with using the existing aspx master pages in our new project. This Article poses a viable solution. Has anyone found a newer, elegant, or more efficient way of achieving this goal?
I don't think there are new ways to integrate master pages.
Good approach is to have master page and _layout file that share most of the actual content via partial views/user controls as covered in Mixing Razor Views in WebForms.
Looked and looked and honestly could not find any one thing that would allow me to keep the look and functionality of my master page with links and functionality. We have decided to use ASPX pages with iframes that point to MVC pages. Eventually the point will be to eliminate the use of aspx master pages. Thanks everyone for great responses.
Related
Recently I've been working on a big ASP.NET Web Forms site and it has some pages that apparently are not in use anymore, but no one knows for sure (this is an inherited project). Is there a way to know if those .aspx files/pages are being used or referenced?
This is not a Web Application Project but a Web Site Project; so I guess it's more difficult to find what .aspx pages are being used and which ones are not. if anyone has experienced something like this, what was your approach to clean this up?
No, probably not. What would be the criteria for that, if no one knows for sure? If you developers can't tell, how would some automatic system decide this for you? You don't need to have .aspx referenced in code for them to be used.
You can use search function in VS to find references inside the project, but in a big website like yours it might be kinda slow and problematic. I'm afraid you'll have to go page by page and figure it out by yourself.
Probably a silly question, being new to development, I am following tutorials and find references to a site.Master file in many of the tutorials I have come across. Is this something that is autogenerated or must I create this file myself? I have access to vs2010 and 2012 and I don't see a site.Master file in any of my projects that i have started. There is however a _layout.cshtml file. I only ask as in every tutorial that mentions this file, doe not mention creating it, just that the file exists.
Here is the deal.
You are probably reading tutorials about MVC or MVC 2 where the view engine is aspx and master pages still are used as a template.
Since MVC 3 a new engine is introduced: Razor. Also this _Layout.cshtml page takes the role of Site.master (master page). With Visual Studio 2010/2012 if you select an MVC project it defaults to Razor syntax and includes _Layout.cshtml as a Shared View.
You can still follow these 'old' tutorials, but mind this difference and act accordingly when recreating the steps.
It could be auto generated if the template you created your project from included a master file. Look in the Solution Explorer (If the solution Explorer isn't visible, hit View -> Solution Explorer) and see if you have a file in your site that ends in the extension ".Master". If not, right click your project in the Solution Explorer then click Add New Item. On the left select your language (Visual Basic or C#) then in the right select Master Page. Give it a name at the bottom such as site.Master. Then click Add. You'll have a master page.
After that, you'll probably want to hook up your other pages to use the new master page. But I'll leave that to your tutorials.
ASP.NET Master Pages: http://msdn.microsoft.com/en-us/library/wtxbf3hh.ASPX
site.master files are usually auto-generated for you when you make a new default ASP.NET website in Visual Studio. Depending on where are in your project, you may need to create one yourself, if Master Pages is the route you want to take. They aren't mandatory, they just make things easier IMO.
MVC has no concept of a masterpage, and site.Master doesn't exist. If you find a reference to site.Master on a tutorial you are using 'regular' ASP.NET (or, as I like to call it, if I'm trying to be polite 'old-fashioned' ASP.NET), not ASP.NET MVC
Yes , It is auto-generated when you create a new ASP Website Project in VS
I've been doing the html and css for a site, sending it off to a guy to implement in a web server. I get a call from the designer freaking out about the progress, saying the clients aren't happy. He wants me to personally integrate my css with what's on the site. The site is done in ASP.net, time is short, and I'm a little in over my head. I have an understanding of how php works, but have never worked extensively with it.
Looking at the stuff on the ftp, I can't even find equivalent of the index.html file (I know that when I go to the site itself, there is nothing after the base url, i.e., www.site.com/ brings me to the homepage.)
Can anyone give me a few tips or links as to what I am to do with this, or where to even being navigating this site?
EDIT: It's -not- a .Net Web Application, from the looks of it.
ASP.Net can be run in a compiled or a scripted environment. It is important to understand which environment your client has. If it is completely scripted, then you are likely looking for the default.aspx file and it's contents. If it is a compiled environment, you may be in for a ride. A compiled site may incorporate "master pages" as a templating engine, and then you'll need to apply your html/css modifications in several places.
You should start with the default.aspx page if there is one. Look for master page directives (it'll be named something like masterpage.master). If there isn't one, then you're in luck you'll just need to implement your changes on a page by page basis. The aspx page will be in a templated xml format so avoid touching tags that involve touching
If you are making changes to divs and structures of that nature, you may need to modify the CssClass attribute of the controls. I would recommend however that you make a back up, give it a shot, and under no circumstances attempt to do something that you aren't really ready to do. You will only anger the client and ruin your rep. It may actually be prudent to contact an actual ASP.Net developer to analyze the files separately and determine what you need to do.
I suggest that you read the Wikipedia article about ASP.NET to get familiarized with it as it summarizes the basic building structures.
Then, just to get you started: take a look at the more recent ASP.NET MVC (Model-View-Controller) paradigm. There's also development in what is called ASP.NET WebForms.
For example: when you go to www.site.com/ (known as friendly URLs) it may be redirecting you to an action method inside a controller. It's called routing. There's also URL rewrite.
In the MVC world a Controller can send/redirect the user to a specific View/Page.
A View (.aspx form/page) that contais HTML markup and CSS on the server side is basically an HTML page (.htm) page that'll be rendered on the client side.
HI,
I have a ASP.NET webiste I created from craft and it now look a big mess. I want to reorganize this but don't know the good way to do it. Some first look well but later cause trouble with master page, image path...
Now I'm thinking of 2 ways:
Using UrlWriter: but it seems lead to a bulk of path rewrite and usually lead to Resource not found or something
Using a page as main entry and using Server.Tranfer to pull the right page content, despite of its location
Which is better? Do you have another method?
Please help!
There's another approach, System.Web.Routing, added in ASP.NET 3.5 SP1. Basically, you implement the IRouteHandler interface and manually route the request to an appropriate handler.
This is how ASP.NET MVC handles request routing. There's a guide here that uses it for Web forms.
By the way, consider looking at ASP.NET MVC and check if it's appropriate for your situation.
I have some ASP.NET Master Pages located in one assembly. I need to use these Master Pages with my WebForm pages located in other assemblies that have a reference to the first assembly. I cannot seem to figure out a way to do this.
Is there a nice way that I can do this?
If no pretty solution exists I would also like to hear about possible hacks?
Master Pages are based upon Usercontrols, therefore they cannot be shared across applications.
That said, Dan Wahlin has a way around that particular limitation listed on his blog.
Sharing Master Pages Across IIS Applications by Dan Wahlin will give you some ideas..
Also, check this excellent article by Scott Allen. You can check the last section at the end on sharing master pages.
There are no pretty solutions to this problem.
What you can do is put it into a separate web application project and pre-compile it. Then take the precompiled dlls and ILMerge them into a single dll that you can reference in your app.
The actual master page that you reference will have a class name like this: MyMasterPage_aweknk so look it up in reflector. The class that looks like "MyMasterPage" is really just the code-behind.
It's really disgusting, but it's what we've done to reuse user controls in multiple applications.