Pregunta

Estoy utilizando SharePiont Server 2007 Enterprise con Windows Server 2008 Enterprise. Estoy desarrollando el uso de VSTS 2008 + + C # .NET 3.5. Quiero añadir algo de código C # para default.aspx (más detalles, añadiendo algunas lógicas a método Page_Load de default.aspx) y su código detrás de archivo. Pero no he encontrado default.aspx y su código detrás de archivo en el disco? Dónde están y cómo modificar?

Por cierto: otra solución es crear un archivo Default.aspx y su código relacionado detrás de archivo por mí mismo? Pero en esta situación cómo tomar prestado el contenido existente / UI de default.aspx actual (Estoy satisfecho con el contenido actual / UI de default.aspx)?

No estoy seguro de qué solución es la mejor y más fácil en mi obligación de incluir código C # a Load. Cualquier consejo o guías?

gracias de antemano!

¿Fue útil?

Solución

¿Es sólo un archivo default.aspx o usted quiere hacer esto con todos ellos?

Si se trata de todos ellos, entonces tal vez un HttpModule podría ser una mejor idea. Puede tocar en el evento de carga de página en página, sobre la base de lo que necesita reglas.

Si es sólo uno de ellos, entonces usted necesita para compilar una DLL con una clase que hereda de Microsoft.SharePoint.WebPartPages.WebPartPage. A continuación, en su default.aspx, editar usando Diseñador SP y luego cambiar la directiva de página a heredar de su clase.

Otros consejos

Changing content in a single page could be done in many ways. For code changes in several pages http modules would not be my first choice (it would probably be one of my last due to performance depending on what needs to be done).

Much more elegant (and less intrusive) methods exists, such as code behind in master page or page layout or inheriting from publishing page.

For changing a single page you could either simply insert a custom control on an existing page, create a site page or even create an application page.

As Steve say, theres many approaches. The solution you choose should be chosen based on what you more specifically is trying to do, and since you dont give us any specifics it is hard to give good advice on how to proceed.

Try for a second to forget how you technically would solve this in a "normal" asp.net application and tell us what you want to achieve more specifically. Often SharePoint development is special and a shortcut (like using SharePoint Designer) can easily get you in trouble later on.

Also in general you need to think in how to deploy your changes. It sounds a bit to me (also on other questions you ask) like you deploy these changes directly on your production server (i might be wrong, but thats the impression i get).

SharePoint has ways of deploying the changes you talk about here (for example creating a new master page with code behind) using Features and Solution packages.

This not only helps you when you want to move your code from environment to environment (eg. from dev test to integration test to pre-prod to production) but also secures your web front end servers are in sync, and also gives you a way to recreate your site if your harddisks should die on you and your backup doesnt work and you forgot to backup your transaction logs (trust me it will happen some day).

I wrote a post on how to create a simple page with code behind for SharePoint; check it out at: The simplest form of a SharePoint application - part 2

Good luck

you should look at this great tutorial on how to create codebehind to masterpage in visual studio. you even dont need the wsp builder extension. It could be done in very low programming way.

Licenciado bajo: CC-BY-SA con atribución
scroll top