using SAMAccountName value to pass into Mailto [closed] - mailto

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 2 years 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"]
Email User
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.

Related

Set a default caption for ALL messagebox? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 6 years ago.
Improve this question
In c# 4.0 I would like to set, at an application level, a default caption for any message boxes the program creates. And by caption I mean the title of the message box.
So should a error message be displayed to the user they will all have the same title.
I know I can do it by using this Message Box overload:
MessageBox.Show(errorMessage, caption);
But I am wondering if there is a more crisp, clean, way to do it?
Rather than having to add a parameter to lots of calls?
You can't really set a default. But you can make a helper to set the title for you, if you really want
public static class MessageBoxEx
{
public static void Show(string message)
{
MessageBox.Show(message, "My Application Name");
}
}
You can of course set the caption however you want, such as from a resource file for multiple languages and locales.

Android Studio: Can I use one java class for multiple layouts? [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 6 years ago.
Improve this question
I'm a beginner in Android Studio and am trying to figure out how to edit different layouts(.xml files) with one java class(.java). I am trying to get the id of an ImageView on another layout, but the findViewById of the ImageView returned null. What do I need to do? Also, I have two layout files because I am using a popupWindow. So, I need to access the ImageView of the popupWindow.
Thanks!
It sounds like you are just using Activity's findViewById, which would search the activity's layout for your ImageView. You would need to call findViewById on your inflated popup view:
View popupView = getLayoutInflater().inflate(R.layout.popup, null);
//Get your image view from the inflated popup
ImageView image = (ImageView) popupView.findViewById(R.id.imageView);

How can I extract the main body of an Orchard Page via a Url

What I'm looking to do is have 2 views of an orchard page.
The first will include headers and footers, the second just the main body content.
The reason is so that we can maintain the body in one place, and it will be used either as a stand alone site, or just embedded within another.
I'm thinking that it would be done by accessing the page using a different route, or appending a querystring parameter.
Any other options are welcomed.
The method I am about to describe is arguably a hack and may go against some of the intentions of the creators of Orchard, but it will get the job done.
Orchard uses the ThemeFilter with the Themed attribute to decide whether the current controller action's output will be 'themed' --- i.e., be displayed with headers and footers. The controller used by Orchard to display content items has this attribute enabled, which is why content items are displayed themed. What you are asking to do is to suppress this 'themed' mode based on the presence of a query string parameter.
ThemeFilter kicks in at a very early stage of the page request and applies itself by setting a value in the current request's http context.
ThemeFilter.cs:
public static void Apply(RequestContext context) {
// the value isn't important
context.HttpContext.Items[typeof (ThemeFilter)] = null;
}
This class does not provide a way of unApplying this value. If you are willing to modify the Orchard source code, you may add this method yourself:
public static void Unapply(RequestContext context) {
context.HttpContext.Items.Remove(typeof (ThemeFilter));
}
Then you can simply create your own action filter that checks for the existence of a query string and then call this method if appropriate, something like:
using System.Web.Mvc;
using Orchard.Mvc.Filters;
using Orchard.Themes;
namespace Demo {
public class UnthemeFilter : FilterProvider, IActionFilter {
public void OnActionExecuting(ActionExecutingContext filterContext) {
}
public void OnActionExecuted(ActionExecutedContext filterContext) {
if (filterContext.RequestContext.HttpContext.Request["unthemed"] != null) {
ThemeFilter.Unapply(filterContext.RequestContext);
}
}
}
}
Now by adding ?unthemed=true, you will be able to suppress the theming.
If you are unwilling or unable to modify the Orchard source code, it is still possible to do the same thing by directly removing the typeof (ThemeFilter) from the HTTP context in your filter. However, this breaks encapsulation and should probably be avoided in object-oriented programming.

How to extend or override BeginForm to include a AntiForgeryToken field

I was reading this article (http://weblogs.asp.net/dixin/archive/2010/05/22/anti-forgery-request-recipes-for-asp-net-mvc-and-ajax.aspx) about how to prevent CSRF attacks. It seems like the solution is to create a tag inside each form.
<%: this.Html.AntiForgeryToken(Constants.AntiForgeryTokenSalt)%>
However, I really don't want to copy and paste that code inside of each form. I would like to extend or override the BeginForm to create a BeginSecureForm that automatically adds the AntiForgeryToken. I am not sure how to add content inbetween of the BeginForm and EndForm.
Any ideas?
You should use this instead, to place the token at the right place, after the form :
public static MvcForm BeginAntiForgeryForm(this HtmlHelper htmlHelper)
{
var mvcForm = htmlHelper.BeginForm();
htmlHelper.ViewContext.Writer.Write(htmlHelper.AntiForgeryToken().ToHtmlString());
return mvcForm;
}

Can I dismiss the iPhone keyboard by touching the background of DialogViewController (MonoTouch.Dialog)? [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
MonoTouch.Dialog: Dismissing keyboard by touching anywhere in DialogViewController
I'm using DialogViewController from MonoTouch.Dialogs. I'd like to be able to dismiss the keyboard by clicking on the background of the dialog.
I usually employ the technique of filling the view with a large custom button and placing it behind all the other elements. However, I can't make this work in the DialogViewController. I did this in LoadView and it just froze all the other controls.
Is there a relatively straightforward way of achieving what I want?
In view controller:
public override void TouchesBegan (NSSet touches, UIEvent evt)
{
base.TouchesBegan (touches, evt);
myField.ResignFirstResponder();
}
Edit: From what I've read, you can use the TouchesBegan event for the cell subview instead of the table itself. I'm not positive that works. Good luck :)
miguel.de.icaza answered this question on a different thread:
https://stackoverflow.com/a/10864640/1134836.
His solution:
var tap = new UITapGestureRecognizer ();
tap.AddTarget (() =>{
dvc.View.EndEditing (true);
});
dvc.View.AddGestureRecognizer (tap);

Resources