user-1: why is it mentioned in the pali canon that Without the direct guidance of a teacher, this practice can be dangerous, as the canon of Buddhist literature includes a story of the Buddha teaching this mediation to pupils, a lot of whom commit suicide while the Buddha is in retreat.does this mean that I being a layperson, can't perform this?moreover, how can I not develop aversion while practising this but still reap it's benefit?

user8157: As a layperson, you can practise 'asubha' without a teacher however you must understand its purpose is to end lust rather than to end life. A stock phrase in the suttas is:

Asubhaṃ bhāvanaṃ bhāvehi. Asubhaṃ hi te bhāvanaṃ bhāvayato yo rāgo so pahīyissati.
Develop the meditation of the unattractive. For when you are developing the meditation of the unattractive, passion/lust will be
  abandoned. 
MN 62; MN 118

In my experience, the primary issue/problem with asubha practice, as occured in the Vesali Sutta, is not so much aversion but, instead, the loss of positive regard towards physical forms in such a way that results in perceiving life as having no purpose.
Therefore, the Buddha teaches in the Vesali Sutta that once 'asubha' practise has served its purposes in generating disgust towards the physical body & abolishing lust, the mind should then develop Anapanasati to make the mind peaceful & to direct the mind to develop final gnosis.

user-1: The direct danger comes from developing aversion to one's own body and other bodies. In short starting to view your own body and that of others as a "sack of shit" or just a general "sour grapes attitude" towards yourself and others. People have apparently commited suicide as a result of these views.
To avoid it, the contemplation needs to be structured with an element of compassion(Karuṇā) so that bodily vulnerabilities are contemplated and one developes a healthy caring attitute towards the concept of a body. Elements of Metta may be needed to balance out aversion hostility if such was to manifest in behavior. It seems that the aversion does have a natural tendency to manifest itself and a correction from a teacher is usually needed at some point if one is to do it on his own. 
If one's mind is powerful enough there can rise alot of visions and signs, which can be used to enter Jhana, but if not done correctly these will be very frightening and uncontrollable and one will go crazy in most cases. IE: Vivid visions of rotting corpses, corpses dragged around, people attacking you etc, not during meditation but during daily life. These states are described as potential complications by Ven. Maha Bua in the book "Wisdom creates Samadhi"
In general it can get tricky, and the meditation is very powerful so there is no saying how a session will affect one. The views can change quickly, changing them back can prove to be difficult. 
That being said i think its a wonderful technique if one does it under competent guidance. Preferably someone who has trained it himself and has trained many other people and can react adequately to complications.
I dont think this is something i would recommend to people, i think it has its place and probably is optimal way to train for some personality types if they wanted to train Samatha but in general its not the only option and runs a real, unnecessary risk. I think its worth noting that the bahavior is the last thing to change, views change much faster so by the time the problem behaviors manifest it may be hard to change it back and many teachers wouldnt even know how to do it.

user295: 
why is it mentioned in the pali canon that Without the direct guidance of a teacher, this practice can be dangerous,

I am not sure if this is mentioned as dangerous in the canon. It is in the commentaries which say this is dangerous. It can be inferred as dangerous because of the above incident.

does this mean that I being a layperson, can't perform this?

You can do this. Only if done right it is not dangerous.

moreover, how can I not develop aversion while practising this but still reap it's benefit?

This is recommended if you inclined to see beauty in the physical form. That is, when you see something you evaluate it is beautiful you get strong attachment.
What is involved here is perception of beauty and the sensation.
Develope Opposite Perception and View
When you see a certain form or shape as beautiful then develop the perception  and view that is is not. This way, as your practice mature, your mental reaction to something beautiful will lesen. The form can you your form (own beauty or looks), someone else or even imaginary form.


when a monk sees a form with the eye, (in him) the agreeable arises, the disagreeable
    arises, the agreeable-and-disagreeable [the neutral] arises.
...
If he wishes thus, ‘May I dwell perceiving the repulsive in the unrepulsive,’ he dwells perceiving the repulsive therein
... mind-object .. mind ...


Indriya Bhāvanā Sutta, Sampasadanīya Sutta
Cemetery Contemplation
Also use external form to reduce attachment to ones own body, again at the level of correcting the perception and view as well as the reflexive response of the mind, i.e., to reduce reflexing arising of craving for sensation due to perceptions on form, and should not lead to reflexing arising of aversion for sensation due to perceptions on form.

he compares this very body with that, thinking:
  "Such is the nature of this body: it will become like that—this is unavoidable."

Mahā Sati’patthāna Sutta
Changes Perception and View due to Internal Content
Also think if what is within the body is external and what was external was inside, you will be chasing animals away from pecking at you flesh! Also imagine what is below the skin. What comes out of the orifices. Imagine body parts piled up. This also a change in perception and view. The last view to break is that the stream of consciousness in internal or self.  
Also see: In what Sutta(s) is there a References to Imagine the Body Inside Out and What is Below the Skin, Sampasadanīya Sutta
Whole vs. Parts and Effect on Perceptions and View
The body is made of parts. Sum of the parts are beautiful but not individually. The parts on their own does not have beauty, but put together only the perception and view of beauty arise. This way you reduce the mental reaction and attachment, to the sensation due to the mental reaction, that follows.
Also see: Mahā Sati’patthāna Sutta
Change in Form due To Decay Changes Perception and Views
Developing the view that the body is impermanent, subjected sickness, decay, old age and death. When you see someone beautiful then when they are sick, oozing excretions or on a pile of excretions, old and dead. Again this a way to adjust your perception and view so you mental reaction and the craving that result from the sensations due to how you mind's reactions are diminished.
Also see: Maha Dukkha-k,khandha Sutta, Does any Theravada Suttas / sources refer to Oozing orifices? What are the Suttas?
Method on Insight
Also when you evaluate some form as beautiful, plain or ugly you get a pleasant, neutral and unpleasant sensation. Use this to eradicate you latent tendencies for craving.


On seeing a form with the eye,
one explores a form that gives rise to pleasure,
one explores a form that gives rise to pain [displeasure],
one explores a form that gives rise to equanimity.
...
On cognizing a mind-object with the mind,
one explores a mind-object that gives rise to pleasure,
one explores a mind-object that gives rise to pain [displeasure],
one explores a mind-object that gives rise to equanimity


Sal-āyatana Vibhanga Sutta


the latent tendency to lust reinforced by being attached to pleasant feelings;


Pahāna Sutta
In the methods mentioned above, the 1st can be dangerous (from most dangerous to the lesser dangerous ones), if you develop aversion towards form, due to the pratice. This is what happened to the monks who committed suicide. They got repulsed by their own body. Meditation on repulsiveness is to bring balance to your mind (being equanimous know it is impermanent regardless of the mental reaction) than moving from one polarity to another (i.e., reflexively seeing beauty and develop craving to reflexively seeing repulsiveness and developing aversion). Developing Insight is the safest way to practice this form of meditation as you are not trying to adjust you reactive / reflexive response of the mind with the risk of overdoing it. A experienced teacher may help detect if you have overdone it and reduce the risk.
Also see: Patikulamanasikara, Vipallasa Sutta

-1: <p>why is it mentioned in the pali canon that Without the direct guidance of a teacher, this practice can be dangerous, as the canon of Buddhist literature includes a story of the Buddha teaching this mediation to pupils, a lot of whom commit suicide while the Buddha is in retreat.does this mean that I being a layperson, can't perform this?moreover, how can I not develop aversion while practising this but still reap it's benefit?</p>
 8157: <p>As a layperson, you can practise '<em>asubha</em>' without a teacher however you must understand its purpose is to end lust rather than to end life. A stock phrase in the suttas is:</p>

<blockquote>
  <p><em>Asubhaṃ bhāvanaṃ bhāvehi. Asubhaṃ hi te bhāvanaṃ bhāvayato yo rāgo so pahīyissati.</em></p>
  
  <p><em>Develop the meditation of the unattractive. For when you are developing the meditation of the unattractive, passion/lust will be
  abandoned.</em> </p>
  
  <p><em>MN 62; MN 118</em></p>
</blockquote>

<p>In my experience, the primary issue/problem with <em>asubha</em> practice, as occured in the <a href="http://www.accesstoinsight.org/tipitaka/sn/sn54/sn54.009.than.html" rel="nofollow noreferrer">Vesali Sutta</a>, is not so much aversion but, instead, the loss of positive regard towards physical forms in such a way that results in perceiving life as having no purpose.</p>

<p>Therefore, the Buddha teaches in the <a href="http://www.accesstoinsight.org/tipitaka/sn/sn54/sn54.009.than.html" rel="nofollow noreferrer">Vesali Sutta</a> that once '<em>asubha</em>' practise has served its purposes in generating disgust towards the physical body &amp; abolishing lust, the mind should then develop Anapanasati to make the mind peaceful &amp; to direct the mind to develop final gnosis.</p>
 -1: <p>The direct danger comes from developing aversion to one's own body and other bodies. In short starting to view your own body and that of others as a "sack of shit" or just a general "sour grapes attitude" towards yourself and others. People have apparently commited suicide as a result of these views.</p>

<p>To avoid it, the contemplation needs to be structured with an element of compassion(Karuṇā) so that bodily vulnerabilities are contemplated and one developes a healthy caring attitute towards the concept of a body. Elements of Metta may be needed to balance out aversion hostility if such was to manifest in behavior. It seems that the aversion does have a natural tendency to manifest itself and a correction from a teacher is usually needed at some point if one is to do it on his own. </p>

<p>If one's mind is powerful enough there can rise alot of visions and signs, which can be used to enter Jhana, but if not done correctly these will be very frightening and uncontrollable and one will go crazy in most cases. IE: Vivid visions of rotting corpses, corpses dragged around, people attacking you etc, not during meditation but during daily life. These states are described as potential complications by Ven. Maha Bua in the book "Wisdom creates Samadhi"</p>

<p>In general it can get tricky, and the meditation is very powerful so there is no saying how a session will affect one. The views can change quickly, changing them back can prove to be difficult. </p>

<p>That being said i think its a wonderful technique if one does it under competent guidance. Preferably someone who has trained it himself and has trained many other people and can react adequately to complications.
I dont think this is something i would recommend to people, i think it has its place and probably is optimal way to train for some personality types if they wanted to train Samatha but in general its not the only option and runs a real, unnecessary risk. I think its worth noting that the bahavior is the last thing to change, views change much faster so by the time the problem behaviors manifest it may be hard to change it back and many teachers wouldnt even know how to do it.</p>
 295: <blockquote>
  <p>why is it mentioned in the pali canon that Without the direct guidance of a teacher, this practice can be dangerous,</p>
</blockquote>

<p>I am not sure if this is mentioned as dangerous in the canon. It is in the commentaries which say this is dangerous. It can be inferred as dangerous because of the above incident.</p>

<blockquote>
  <p>does this mean that I being a layperson, can't perform this?</p>
</blockquote>

<p>You can do this. Only if done right it is not dangerous.</p>

<blockquote>
  <p>moreover, how can I not develop aversion while practising this but still reap it's benefit?</p>
</blockquote>

<p>This is recommended if you inclined to see beauty in the physical form. That is, when you see something you evaluate it is beautiful you get strong attachment.</p>

<p>What is involved here is perception of beauty and the sensation.</p>

<h1>Develope Opposite Perception and View</h1>

<p>When you see a certain form or shape as beautiful then develop the perception  and view that is is not. This way, as your practice mature, your mental reaction to something beautiful will lesen. The form can you your form (own beauty or looks), someone else or even imaginary form.</p>

<blockquote>
  <blockquote>
    <p>when a monk sees a form with the eye, (in him) the agreeable arises, the disagreeable
    arises, the agreeable-and-disagreeable [the neutral] arises.</p>
    
    <p>...</p>
    
    <p>If he wishes thus, ‘May I dwell perceiving the repulsive in the unrepulsive,’ he dwells perceiving the repulsive therein</p>
    
    <p>... mind-object .. mind ...</p>
  </blockquote>
</blockquote>

<p><a href="http://www.themindingcentre.org/dharmafarer/wp-content/uploads/2009/12/17.13-Indriya-Bhavana-S-m152-piya.pdf" rel="nofollow noreferrer">Indriya Bhāvanā Sutta</a>, <a href="http://www.themindingcentre.org/dharmafarer/wp-content/uploads/2009/12/14.14-Sampasadaniya-S-d28-piya.pdf" rel="nofollow noreferrer">Sampasadanīya Sutta</a></p>

<h1>Cemetery Contemplation</h1>

<p>Also use external form to reduce attachment to ones own body, again at the level of correcting the perception and view as well as the reflexive response of the mind, i.e., to reduce reflexing arising of craving for sensation due to perceptions on form, and should not lead to reflexing arising of aversion for sensation due to perceptions on form.</p>

<blockquote>
  <p>he compares this very body with that, thinking:
  "Such is the nature of this body: it will become like that—this is unavoidable."</p>
</blockquote>

<p><a href="http://www.themindingcentre.org/dharmafarer/wp-content/uploads/2009/12/13.2-Mahasatipatthana-S-d22-piya.pdf" rel="nofollow noreferrer">Mahā Sati’patthāna Sutta</a></p>

<h1>Changes Perception and View due to Internal Content</h1>

<p>Also think if what is within the body is external and what was external was inside, you will be chasing animals away from pecking at you flesh! Also imagine what is below the skin. What comes out of the orifices. Imagine body parts piled up. This also a change in perception and view. The last view to break is that the stream of consciousness in internal or self.  </p>

<p>Also see: <a href="https://buddhism.stackexchange.com/questions/19003">In what Sutta(s) is there a References to Imagine the Body Inside Out and What is Below the Skin</a>, <a href="http://www.themindingcentre.org/dharmafarer/wp-content/uploads/2009/12/14.14-Sampasadaniya-S-d28-piya.pdf" rel="nofollow noreferrer">Sampasadanīya Sutta</a></p>

<h1>Whole vs. Parts and Effect on Perceptions and View</h1>

<p>The body is made of parts. Sum of the parts are beautiful but not individually. The parts on their own does not have beauty, but put together only the perception and view of beauty arise. This way you reduce the mental reaction and attachment, to the sensation due to the mental reaction, that follows.</p>

<p>Also see: <a href="http://www.themindingcentre.org/dharmafarer/wp-content/uploads/2009/12/13.2-Mahasatipatthana-S-d22-piya.pdf" rel="nofollow noreferrer">Mahā Sati’patthāna Sutta</a></p>

<h1>Change in Form due To Decay Changes Perception and Views</h1>

<p>Developing the view that the body is impermanent, subjected sickness, decay, old age and death. When you see someone beautiful then when they are sick, oozing excretions or on a pile of excretions, old and dead. Again this a way to adjust your perception and view so you mental reaction and the craving that result from the sensations due to how you mind's reactions are diminished.</p>

<p>Also see: <a href="http://www.themindingcentre.org/dharmafarer/wp-content/uploads/2009/12/6.9-Maha-Dukkhakkhandha-S-m013-piya.pdf" rel="nofollow noreferrer">Maha Dukkha-k,khandha Sutta</a>, <a href="https://buddhism.stackexchange.com/questions/5530">Does any Theravada Suttas / sources refer to Oozing orifices? What are the Suttas?</a></p>

<h1>Method on <a href="https://en.wikipedia.org/wiki/Vipassan%C4%81" rel="nofollow noreferrer">Insight</a></h1>

<p>Also when you evaluate some form as beautiful, plain or ugly you get a pleasant, neutral and unpleasant sensation. Use this to eradicate you latent tendencies for craving.</p>

<blockquote>
  <blockquote>
    <p>On seeing a form with the eye,</p>
    
    <p>one explores a form that gives rise to pleasure,</p>
    
    <p>one explores a form that gives rise to pain [displeasure],</p>
    
    <p>one explores a form that gives rise to equanimity.</p>
    
    <p>...</p>
    
    <p>On cognizing a mind-object with the mind,</p>
    
    <p>one explores a mind-object that gives rise to pleasure,</p>
    
    <p>one explores a mind-object that gives rise to pain [displeasure],</p>
    
    <p>one explores a mind-object that gives rise to equanimity</p>
  </blockquote>
</blockquote>

<p><a href="http://www.themindingcentre.org/dharmafarer/wp-content/uploads/2009/12/29.5-Salayatana-Vibhanga-S-m137-piya.pdf" rel="nofollow noreferrer">Sal-āyatana Vibhanga Sutta</a></p>

<blockquote>
  <blockquote>
    <p>the latent tendency to lust reinforced by being attached to pleasant feelings;</p>
  </blockquote>
</blockquote>

<p><a href="http://www.themindingcentre.org/dharmafarer/wp-content/uploads/2010/02/31.1-Pahana-S-s36.3-piya.pdf" rel="nofollow noreferrer">Pahāna Sutta</a></p>

<p>In the methods mentioned above, the 1st can be dangerous (from most dangerous to the lesser dangerous ones), if you develop aversion towards form, due to the pratice. This is what happened to the monks who committed suicide. They got repulsed by their own body. Meditation on repulsiveness is to bring balance to your mind (being equanimous know it is impermanent regardless of the mental reaction) than moving from one polarity to another (i.e., reflexively seeing beauty and develop craving to reflexively seeing repulsiveness and developing aversion). Developing Insight is the safest way to practice this form of meditation as you are not trying to adjust you reactive / reflexive response of the mind with the risk of overdoing it. A experienced teacher may help detect if you have overdone it and reduce the risk.</p>

<p>Also see: <a href="https://en.wikipedia.org/wiki/Patikulamanasikara" rel="nofollow noreferrer">Patikulamanasikara</a>, <a href="http://www.themindingcentre.org/dharmafarer/wp-content/uploads/2009/12/16.11-Vipallasa-S-a4.49-piya.pdf" rel="nofollow noreferrer">Vipallasa Sutta</a></p>
