That is a great and simple way to do it. Visitors to your site can
browse and search but they cannot see the classified ad itself.
Depending on the nature of your site, it would either drive people away
without looking at any ads, or it would encourage them to register and
log in to view the ads.
In my case, I want visitors to view lots
of the ads. I initialy did what nbrglobalinc showed in the above
post. Then I decided I want to let them look at the ad, but they
cannot respond to the ad unless logged in.
Now, since they
must be logged in, the response email will automatically include their
username, email address and the names they gave for first and last name
when they registered. The next best thing I did was set those fields
to Readonly=True . So users will see that the response will have this
automatically entered and that they can NOT change it.
Because
the registered username is included in the email, if I get any
complaints from those that placed ads, I can very quickly locate the
member that sent the spam or whatever and then click "disaprove" and
they will never be able to use the site again unless they re-register
with a new email address.
in ShowAd.aspx.vb find the section for the "RespondButton_Click" and just put in the "IF Then Else" . If they are not logged in they are sent to the log in page.
--------------------------------------------------
Protected Sub RespondButton_Click(ByVal sender As Object, ByVal e As EventArgs)
If User.Identity.IsAuthenticated Then
SetActivePanel(ResponsePanel)
Else
FormsAuthentication.RedirectToLoginPage()
End If
-----------------------------------------------------------------------------------------------------
Now that we know they are logged in, let's force the username to be added to the email.
Also, I added at the bottom of an email a link to the very ad from which the response was generated. If someone has 100 ads on the site, it is nice to be able to click the link in the email and see the ad the person is talking about.
Here is how I added the information to the response email.
In App_code/BLL/Ads.vb find this section of the code and add the part of .Username
---------------------------------------------------------------------------------------------------------------
Public Shared Function SendResponse(ByVal adId As Integer, ByVal
senderName As String, ByVal senderAddress As String, ByVal comments As
String) As Boolean
Dim sent As Boolean = False
Dim s As SiteSettings = SiteSettings.GetSharedSettings()
Dim ad As AdsDataComponent.AdsRow = GetAdById(adId)
If Not (ad Is Nothing) Then
Dim adUser As MembershipUser = Membership.GetUser(ad.MemberName)
If Not (adUser Is Nothing) Then
Dim sb As New StringBuilder()
sb.AppendFormat("A response to your listing '{0}' at {1}", ad.Title, s.SiteName)
sb.AppendLine()
sb.AppendLine("The contact information of the user is:")
sb.AppendLine(("Registered Username: " + Membership.GetUser().UserName))
sb.AppendLine(("Name: " + senderName))
sb.AppendLine(("Email: " + senderAddress))
sb.AppendLine()
sb.AppendLine("User comments/questions:")
sb.AppendLine(comments)
sb.AppendLine()
sb.AppendLine("You can respond to the user by using the email address provided.")
sb.AppendLine("If you have sold your item, please log in and unlist your ad.")
sb.AppendLine(("Your username is: " + adUser.UserName)) 'added by racer184 October 29, 2009
'comment out these next 2 lines as they are redundant after I put in the code in the following lines
'sb.AppendLine(s.SiteName)
'sb.AppendLine(ClassifiedsHttpApplication.SiteUrl)
'racer184 adding into the response email a link to the actual ad.
'this is helpful to people that have a great number of ads on the site
sb.AppendLine("Here is the link to your ad")
sb.Append(ClassifiedsHttpApplication.SiteUrl)
If Not (ClassifiedsHttpApplication.SiteUrl.EndsWith("/")) Then
sb.Append("/")
End If
sb.Append("ShowAd.aspx?id=")
sb.Append(ad.Id.ToString())