开发者

using SAMAccountName value to pass into Mailto [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.

Want to improve this question? Update the question so it focuses on one problem only by editing this post.

Closed 1 year ago.

开发者_运维知识库 Improve this question

I'm using MVC. I need to get the current AD username (probably using SAMAccountName) and pass the value on a mailto javascript (should pass value on an email body).

Where should I put the SAMAccountName code and how will I use the value?


Technically you should be putting this into the ViewData. If you have to do this all over the place, I'd recommend subclassing Controller and overriding OnActionExecuted to get the current user's userid and putting it into the viewstate:

public class BaseController : Controller
{
  protected override void OnActionExecuted( ActionExecutedContext filterContext )
  {
    ViewData["userid"] = Request.User.Identity;
  }   
}

Then have your controller extent BaseController

public class MyController : BaseController
{
  public ActionResult View( int id )
  {
    return View();
  }
}

Then in your view you can access the ViewData["userid"]

<a href="mailto:<%=ViewData["userid"]%>@mycompany.com">Email User</a>

All this being said, if you're going to be doing access control and the like, you might build a "LoggedInUser" class that you can add helper methods to. Then stick it in the session (assuming you're ok using session). You can do this logic in the Global.asax Session_Start method.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜