开发者

Hide email or website addresses unless authenticated

I'm developing a job board website with ASP.Net MVC and want to block any email or website addresses from being visible to unregistered users.

So for example i开发者_运维知识库f an employer posts a job and includes something in the description like 'To apply send an email to myemail@email.com', I want it to display 'To apply send an email to hidden link - please login or register' or words to that effect. When they login the links then become available.

I'm still very much at the learner stage with ASP.Net MVC so I'm not really sure where to start with this. I'm not sure if this is the right thing to do or if there is an alternative approach.

Many thanks for any help.


only777,

you may be best served by creating an DisplayTemplate for email addresses and running your code thro those. here's an example of what i mean. Inside your view:

<%: Html.DisplayFor( m => m.Email, "ViewIfAuthenticatedTemplate" ) %>

and then under views/shared/DisplayTemplates, add an item called ViewIfAuthenticatedTemplate.ascx and add the following code to it:

<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<string>" %>

<% if(Request.IsAuthenticated) { %>
    <%: Model %>
<% } else {%>
    <%: Html.ActionLink("hidden link - please login or register", "MyAction", "MyController") %>
<% } %>

not sure if the syntax is 100% correct, but you get the gist..

[edit] - in fact, you could use this DisplayTemplate for ANY text that had to be hidden if not authenticated.


Use a regex search to look for email addresses in the posting and replace that with the link you want for the unregistered users.

[Updated]

  public ActionResult ShowPosting()
    {
    var description = descriptionFromDB();

    if(!registeredUser)
    {
    model.Description = logicToReplaceTheEmailAddress(description);
    }
    else
    {
    model.Description= description;
    }

    return View(model);

}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜