我想让当前用户获取用户的信息,例如电子邮件.但我不能在asp.net核心中这样做.我很困惑这是我的代码.
HttpContext在控制器的构造函数中几乎为null .在每个动作中获得用户并不好.我想获得用户的信息并将其设置为ViewData;
public DashboardController()
{
var user = HttpContext.User.GetUserId();
}
Run Code Online (Sandbox Code Playgroud) 目前,我们正在体验DeadSystemExceptionHockeyApp崩溃报告.它出现在Android 7.0和Android 7.1上.我们在以前的应用程序版本中没有遇到此异常(它们当前都被用户使用),所以我猜这个异常是由一些代码更改引起的.但堆栈跟踪并不是很有用.任何的想法?谢谢你的任何消化.
来自HockeyApp的堆栈跟踪:
java.lang.RuntimeException: android.os.DeadSystemException
at android.app.ActivityThread$StopInfo.run(ActivityThread.java:3781)
at android.os.Handler.handleCallback(Handler.java:751)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6119)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
Caused by: android.os.DeadSystemException
... 8 more
Run Code Online (Sandbox Code Playgroud) 我想要使用我的网站的客户的公共IP地址.下面的代码显示了LAN中的本地IP,但我想要客户端的公共IP.
//get mac address
NetworkInterface[] nics = NetworkInterface.GetAllNetworkInterfaces();
String sMacAddress = string.Empty;
foreach (NetworkInterface adapter in nics)
{
if (sMacAddress == String.Empty)// only return MAC Address from first card
{
IPInterfaceProperties properties = adapter.GetIPProperties();
sMacAddress = adapter.GetPhysicalAddress().ToString();
}
}
// To Get IP Address
string IPHost = Dns.GetHostName();
string IP = Dns.GetHostByName(IPHost).AddressList[0].ToString();
Run Code Online (Sandbox Code Playgroud)
输出:
IP地址:192.168.1.7
请帮我获取公共IP地址.
有什么办法可以使用API访问任何维基百科页面的缩略图吗?我的意思是盒子右上方的图像.那有什么API吗?
当我点击我的抽屉切换时,我得到以下异常
java.lang.IllegalArgumentException:在重力下没有找到抽屉视图
这是我的activity_drawer.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:minHeight="?attr/actionBarSize"
android:background="?attr/colorPrimary"/>
<FrameLayout
android:id="@+id/content"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
<fragment
android:id="@+id/navigation"
android:layout_width="240dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:name="com.xyz.ui.navigation.NavigationFragment"
tools:layout="@layout/fragment_navigation" />
</LinearLayout>
</android.support.v4.widget.DrawerLayout>
Run Code Online (Sandbox Code Playgroud)
我的fragment_navigation.xml
<?xml version="1.0" encoding="utf-8"?>
<ListView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="start">
</ListView>
Run Code Online (Sandbox Code Playgroud)
还有我的清单项目
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Large Text"
android:id="@+id/navigation_item_text"
android:layout_gravity="center_horizontal" />
</LinearLayout>
Run Code Online (Sandbox Code Playgroud) 我正在尝试获取AD中特定组的所有用户,然后将Employees列表返回到我的Employee类中的属性.我有:
我的过滤器没有产生任何结果 - 应该是什么?
此外,我在这里尝试了第一个解决方案: 特定Active Directory通讯组中的用户列表,但我需要移动设备,扩展程序等详细信息,这是我无法使用该方法获得的.
public static List<Employee> CreateEmployeeList(string department)
{
List<Employee> employees = new List<Employee>();
string filter = string.Format("(&(ObjectClass=person)(memberOf=CN={0},OU=Users & Groups,OU=Blah,DC=Blah,DC=Blah,DC=Blah))", department);
DirectoryEntry adRoot = new DirectoryEntry("LDAP://" + domain, null, null, AuthenticationTypes.Secure);
DirectorySearcher searcher = new DirectorySearcher(adRoot);
searcher.SearchScope = SearchScope.Subtree;
searcher.ReferralChasing = ReferralChasingOption.All;
searcher.Filter = filter;
SearchResultCollection results = searcher.FindAll();
foreach (SearchResult user in results)
{
// do whatever you need to do with the entry
if (user != null)
{
UserDirectoryEntry = user.GetDirectoryEntry();
string displayName …Run Code Online (Sandbox Code Playgroud) 我正在尝试用FakeDbSet制作一个FakeDbContext进行单元测试.
但是我收到以下错误(见下文).我正在扩展DbSet,所以通常应该实现IDbAsyncEnumerable.当我实现它时,它说没有用.
例外:
System.InvalidOperationException:源IQueryable未实现IDbAsyncEnumerable.只有实现IDbAsyncEnumerable的源才能用于Entity Framework异步操作.有关详细信息,请参阅 http://go.microsoft.com/fwlink/?LinkId=287068.
FakeDbSet类:
public abstract class FakeDbSet<TEntity> : DbSet<TEntity>, IEnumerable<TEntity>, IQueryable, IDbAsyncEnumerable<TEntity> where TEntity : Entity, new()
{
#region Private Fields
private readonly ObservableCollection<TEntity> _items;
private readonly IQueryable _query;
#endregion Private Fields
protected FakeDbSet()
{
_items = new ObservableCollection<TEntity>();
_query = _items.AsQueryable();
}
public Expression Expression { get { return _query.Expression; } }
public Type ElementType { get { return _query.ElementType; } }
public IQueryProvider Provider { get { return _query.Provider; } }
public override …Run Code Online (Sandbox Code Playgroud) 如何[Display(Name="Some Title")]在List scaffold视图的输出中获取DataAnnotations"Some Title"?
我为这个类创建了一个强类型列表支架视图:
public class CompanyHoliday
{
[Key]
public int Id { get; set; }
[Required]
[Display(Name = "Datum")]
[DataType(System.ComponentModel.DataAnnotations.DataType.Date)]
public DateTime Date { get; set; }
[Required]
[StringLength(50)]
[Display(Name = "Feiertag Name")]
public string Name { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
该视图如下所示:
@model IEnumerable<Zeiterfassung.Domain.CompanyHoliday>
@{
ViewBag.Title = "Year";
}
<h2>Year</h2>
<p>
@Html.ActionLink("Create New", "Create")
</p>
<table>
<tr>
<th></th>
<th>
Date
</th>
<th>
Name
</th>
</tr>
@foreach (var item in Model) {
<tr>
<td>
@Html.ActionLink("Edit", "Edit", new …Run Code Online (Sandbox Code Playgroud) 所以,假设我在这样的页面中有一个简单的表单:
<form style="text-align:center;">
<p> STUFF </p>
</form>
Run Code Online (Sandbox Code Playgroud)
我想添加一个按钮,所以当用户点击它时,浏览器的"打印"对话框会出现,我该怎么做?
编辑:我想打印表单,而不是页面.
这个问题在这里的一个简单例子中不易重现,但是想知道是否有人有任何经验和提示,这里是问题:
像这样:
using (TransactionScope txScope = new TransactionScope()) {
...
}
Run Code Online (Sandbox Code Playgroud)
但这给了我:
Microsoft分布式事务处理协调器(MSDTC)已禁用网络事务.
我们的数据库管理员告诉我,MSDTC被禁用,无法安装.
因此,我正在尝试使用MetadataWorkspace创建自己的EntityConnection,并认为每个上下文将使用相同的EntityConnection.然而,这证明几乎不可能试图让它工作,例如,即使理论上两个上下文都在使用EntityConnection,我仍然继续得到上述错误.例如,很难理解实体框架在何处/为何需要MSDTC.
有没有人走过这条路,有经验或代码示例分享?
c# ×4
android ×2
asp.net-mvc ×2
.net ×1
api ×1
asp.net ×1
asp.net-core ×1
forms ×1
html ×1
javascript ×1
msdtc ×1
php ×1
printing ×1
razor ×1
transactions ×1